mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-26 10:43:51 -05:00
Merge branch 'master' into strictObjectLiterals
Conflicts: tests/baselines/reference/typeGuardFunction.types
This commit is contained in:
@@ -11,7 +11,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function getModuleInstanceState(node: Node): ModuleInstanceState {
|
||||
// A module is uninstantiated if it contains only
|
||||
// A module is uninstantiated if it contains only
|
||||
// 1. interface declarations, type alias declarations
|
||||
if (node.kind === SyntaxKind.InterfaceDeclaration || node.kind === SyntaxKind.TypeAliasDeclaration) {
|
||||
return ModuleInstanceState.NonInstantiated;
|
||||
@@ -53,7 +53,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
const enum ContainerFlags {
|
||||
// The current node is not a container, and no container manipulation should happen before
|
||||
// The current node is not a container, and no container manipulation should happen before
|
||||
// recursing into it.
|
||||
None = 0,
|
||||
|
||||
@@ -90,13 +90,13 @@ namespace ts {
|
||||
let lastContainer: Node;
|
||||
|
||||
// If this file is an external module, then it is automatically in strict-mode according to
|
||||
// ES6. If it is not an external module, then we'll determine if it is in strict mode or
|
||||
// ES6. If it is not an external module, then we'll determine if it is in strict mode or
|
||||
// not depending on if we see "use strict" in certain places (or if we hit a class/namespace).
|
||||
let inStrictMode = !!file.externalModuleIndicator;
|
||||
|
||||
let symbolCount = 0;
|
||||
let Symbol = objectAllocator.getSymbolConstructor();
|
||||
let classifiableNames: Map<string> = {};
|
||||
let classifiableNames: Map<string> = {};
|
||||
|
||||
if (!file.locals) {
|
||||
bind(file);
|
||||
@@ -179,7 +179,7 @@ namespace ts {
|
||||
* @param parent - node's parent declaration.
|
||||
* @param node - The declaration to be added to the symbol table
|
||||
* @param includes - The SymbolFlags that node has in addition to its declaration type (eg: export, ambient, etc.)
|
||||
* @param excludes - The flags which node cannot be declared alongside in a symbol table. Used to report forbidden declarations.
|
||||
* @param excludes - The flags which node cannot be declared alongside in a symbol table. Used to report forbidden declarations.
|
||||
*/
|
||||
function declareSymbol(symbolTable: SymbolTable, parent: Symbol, node: Declaration, includes: SymbolFlags, excludes: SymbolFlags): Symbol {
|
||||
Debug.assert(!hasDynamicName(node));
|
||||
@@ -192,13 +192,13 @@ namespace ts {
|
||||
|
||||
// Check and see if the symbol table already has a symbol with this name. If not,
|
||||
// create a new symbol with this name and add it to the table. Note that we don't
|
||||
// give the new symbol any flags *yet*. This ensures that it will not conflict
|
||||
// give the new symbol any flags *yet*. This ensures that it will not conflict
|
||||
// with the 'excludes' flags we pass in.
|
||||
//
|
||||
// If we do get an existing symbol, see if it conflicts with the new symbol we're
|
||||
// creating. For example, a 'var' symbol and a 'class' symbol will conflict within
|
||||
// the same symbol table. If we have a conflict, report the issue on each
|
||||
// declaration we have for this symbol, and then create a new symbol for this
|
||||
// the same symbol table. If we have a conflict, report the issue on each
|
||||
// declaration we have for this symbol, and then create a new symbol for this
|
||||
// declaration.
|
||||
//
|
||||
// If we created a new symbol, either because we didn't have a symbol with this name
|
||||
@@ -259,7 +259,7 @@ namespace ts {
|
||||
// ExportType, or ExportContainer flag, and an associated export symbol with all the correct flags set
|
||||
// on it. There are 2 main reasons:
|
||||
//
|
||||
// 1. We treat locals and exports of the same name as mutually exclusive within a container.
|
||||
// 1. We treat locals and exports of the same name as mutually exclusive within a container.
|
||||
// That means the binder will issue a Duplicate Identifier error if you mix locals and exports
|
||||
// with the same name in the same container.
|
||||
// TODO: Make this a more specific error and decouple it from the exclusion logic.
|
||||
@@ -282,11 +282,11 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
// All container nodes are kept on a linked list in declaration order. This list is used by
|
||||
// the getLocalNameOfContainer function in the type checker to validate that the local name
|
||||
// All container nodes are kept on a linked list in declaration order. This list is used by
|
||||
// the getLocalNameOfContainer function in the type checker to validate that the local name
|
||||
// used for a container is unique.
|
||||
function bindChildren(node: Node) {
|
||||
// Before we recurse into a node's chilren, we first save the existing parent, container
|
||||
// Before we recurse into a node's chilren, we first save the existing parent, container
|
||||
// and block-container. Then after we pop out of processing the children, we restore
|
||||
// these saved values.
|
||||
let saveParent = parent;
|
||||
@@ -295,16 +295,16 @@ namespace ts {
|
||||
|
||||
// This node will now be set as the parent of all of its children as we recurse into them.
|
||||
parent = node;
|
||||
|
||||
|
||||
// Depending on what kind of node this is, we may have to adjust the current container
|
||||
// and block-container. If the current node is a container, then it is automatically
|
||||
// considered the current block-container as well. Also, for containers that we know
|
||||
// may contain locals, we proactively initialize the .locals field. We do this because
|
||||
// it's highly likely that the .locals will be needed to place some child in (for example,
|
||||
// a parameter, or variable declaration).
|
||||
//
|
||||
//
|
||||
// However, we do not proactively create the .locals for block-containers because it's
|
||||
// totally normal and common for block-containers to never actually have a block-scoped
|
||||
// totally normal and common for block-containers to never actually have a block-scoped
|
||||
// variable in them. We don't want to end up allocating an object for every 'block' we
|
||||
// run into when most of them won't be necessary.
|
||||
//
|
||||
@@ -345,7 +345,7 @@ namespace ts {
|
||||
case SyntaxKind.TypeLiteral:
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
return ContainerFlags.IsContainer;
|
||||
|
||||
|
||||
case SyntaxKind.CallSignature:
|
||||
case SyntaxKind.ConstructSignature:
|
||||
case SyntaxKind.IndexSignature:
|
||||
@@ -373,7 +373,7 @@ namespace ts {
|
||||
|
||||
case SyntaxKind.Block:
|
||||
// do not treat blocks directly inside a function as a block-scoped-container.
|
||||
// Locals that reside in this block should go to the function locals. Othewise 'x'
|
||||
// Locals that reside in this block should go to the function locals. Othewise 'x'
|
||||
// would not appear to be a redeclaration of a block scoped local in the following
|
||||
// example:
|
||||
//
|
||||
@@ -386,7 +386,7 @@ namespace ts {
|
||||
// the block, then there would be no collision.
|
||||
//
|
||||
// By not creating a new block-scoped-container here, we ensure that both 'var x'
|
||||
// and 'let x' go into the Function-container's locals, and we do get a collision
|
||||
// and 'let x' go into the Function-container's locals, and we do get a collision
|
||||
// conflict.
|
||||
return isFunctionLike(node.parent) ? ContainerFlags.None : ContainerFlags.IsBlockScopedContainer;
|
||||
}
|
||||
@@ -484,7 +484,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function hasExportDeclarations(node: ModuleDeclaration | SourceFile): boolean {
|
||||
var body = node.kind === SyntaxKind.SourceFile ? node : (<ModuleDeclaration>node).body;
|
||||
let body = node.kind === SyntaxKind.SourceFile ? node : (<ModuleDeclaration>node).body;
|
||||
if (body.kind === SyntaxKind.SourceFile || body.kind === SyntaxKind.ModuleBlock) {
|
||||
for (let stat of (<Block>body).statements) {
|
||||
if (stat.kind === SyntaxKind.ExportDeclaration || stat.kind === SyntaxKind.ExportAssignment) {
|
||||
@@ -536,8 +536,8 @@ namespace ts {
|
||||
// For a given function symbol "<...>(...) => T" we want to generate a symbol identical
|
||||
// to the one we would get for: { <...>(...): T }
|
||||
//
|
||||
// We do that by making an anonymous type literal symbol, and then setting the function
|
||||
// symbol as its sole member. To the rest of the system, this symbol will be indistinguishable
|
||||
// We do that by making an anonymous type literal symbol, and then setting the function
|
||||
// symbol as its sole member. To the rest of the system, this symbol will be indistinguishable
|
||||
// from an actual type literal symbol you would have gotten had you used the long form.
|
||||
let symbol = createSymbol(SymbolFlags.Signature, getDeclarationName(node));
|
||||
addDeclarationToSymbol(symbol, node, SymbolFlags.Signature);
|
||||
@@ -638,7 +638,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getStrictModeIdentifierMessage(node: Node) {
|
||||
// Provide specialized messages to help the user understand why we think they're in
|
||||
// Provide specialized messages to help the user understand why we think they're in
|
||||
// strict mode.
|
||||
if (getContainingClass(node)) {
|
||||
return Diagnostics.Identifier_expected_0_is_a_reserved_word_in_strict_mode_Class_definitions_are_automatically_in_strict_mode;
|
||||
@@ -696,7 +696,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getStrictModeEvalOrArgumentsMessage(node: Node) {
|
||||
// Provide specialized messages to help the user understand why we think they're in
|
||||
// Provide specialized messages to help the user understand why we think they're in
|
||||
// strict mode.
|
||||
if (getContainingClass(node)) {
|
||||
return Diagnostics.Invalid_use_of_0_Class_definitions_are_automatically_in_strict_mode;
|
||||
@@ -760,24 +760,24 @@ namespace ts {
|
||||
function bind(node: Node) {
|
||||
node.parent = parent;
|
||||
|
||||
var savedInStrictMode = inStrictMode;
|
||||
let savedInStrictMode = inStrictMode;
|
||||
if (!savedInStrictMode) {
|
||||
updateStrictMode(node);
|
||||
}
|
||||
|
||||
// First we bind declaration nodes to a symbol if possible. We'll both create a symbol
|
||||
// and then potentially add the symbol to an appropriate symbol table. Possible
|
||||
// and then potentially add the symbol to an appropriate symbol table. Possible
|
||||
// destination symbol tables are:
|
||||
//
|
||||
//
|
||||
// 1) The 'exports' table of the current container's symbol.
|
||||
// 2) The 'members' table of the current container's symbol.
|
||||
// 3) The 'locals' table of the current container.
|
||||
//
|
||||
// However, not all symbols will end up in any of these tables. 'Anonymous' symbols
|
||||
// However, not all symbols will end up in any of these tables. 'Anonymous' symbols
|
||||
// (like TypeLiterals for example) will not be put in any table.
|
||||
bindWorker(node);
|
||||
|
||||
// Then we recurse into the children of the node to bind them as well. For certain
|
||||
// Then we recurse into the children of the node to bind them as well. For certain
|
||||
// symbols we do specialized work when we recurse. For example, we'll keep track of
|
||||
// the current 'container' node when it changes. This helps us know which symbol table
|
||||
// a local should go into for example.
|
||||
@@ -817,7 +817,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// Should be called only on prologue directives (isPrologueDirective(node) should be true)
|
||||
function isUseStrictPrologueDirective(node: ExpressionStatement): boolean {
|
||||
let nodeText = getTextOfNodeFromSourceText(file.text, node.expression);
|
||||
@@ -972,9 +972,9 @@ namespace ts {
|
||||
let symbol = node.symbol;
|
||||
|
||||
// TypeScript 1.0 spec (April 2014): 8.4
|
||||
// Every class automatically contains a static property member named 'prototype', the
|
||||
// Every class automatically contains a static property member named 'prototype', the
|
||||
// type of which is an instantiation of the class type with type Any supplied as a type
|
||||
// argument for each type parameter. It is an error to explicitly declare a static
|
||||
// argument for each type parameter. It is an error to explicitly declare a static
|
||||
// property member with the name 'prototype'.
|
||||
//
|
||||
// Note: we check for this here because this class may be merging into a module. The
|
||||
@@ -1000,7 +1000,7 @@ namespace ts {
|
||||
|
||||
function bindVariableDeclarationOrBindingElement(node: VariableDeclaration | BindingElement) {
|
||||
if (inStrictMode) {
|
||||
checkStrictModeEvalOrArguments(node, node.name)
|
||||
checkStrictModeEvalOrArguments(node, node.name);
|
||||
}
|
||||
|
||||
if (!isBindingPattern(node.name)) {
|
||||
@@ -1039,7 +1039,7 @@ namespace ts {
|
||||
declareSymbolAndAddToSymbolTable(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes);
|
||||
}
|
||||
|
||||
// If this is a property-parameter, then also declare the property symbol into the
|
||||
// If this is a property-parameter, then also declare the property symbol into the
|
||||
// containing class.
|
||||
if (node.flags & NodeFlags.AccessibilityModifier &&
|
||||
node.parent.kind === SyntaxKind.Constructor &&
|
||||
@@ -1056,4 +1056,4 @@ namespace ts {
|
||||
: declareSymbolAndAddToSymbolTable(node, symbolFlags, symbolExcludes);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,7 @@
|
||||
|
||||
namespace ts {
|
||||
/* @internal */
|
||||
export var optionDeclarations: CommandLineOption[] = [
|
||||
export let optionDeclarations: CommandLineOption[] = [
|
||||
{
|
||||
name: "charset",
|
||||
type: "string",
|
||||
@@ -222,11 +222,11 @@ namespace ts {
|
||||
];
|
||||
|
||||
export function parseCommandLine(commandLine: string[]): ParsedCommandLine {
|
||||
var options: CompilerOptions = {};
|
||||
var fileNames: string[] = [];
|
||||
var errors: Diagnostic[] = [];
|
||||
var shortOptionNames: Map<string> = {};
|
||||
var optionNameMap: Map<CommandLineOption> = {};
|
||||
let options: CompilerOptions = {};
|
||||
let fileNames: string[] = [];
|
||||
let errors: Diagnostic[] = [];
|
||||
let shortOptionNames: Map<string> = {};
|
||||
let optionNameMap: Map<CommandLineOption> = {};
|
||||
|
||||
forEach(optionDeclarations, option => {
|
||||
optionNameMap[option.name.toLowerCase()] = option;
|
||||
@@ -242,9 +242,9 @@ namespace ts {
|
||||
};
|
||||
|
||||
function parseStrings(args: string[]) {
|
||||
var i = 0;
|
||||
let i = 0;
|
||||
while (i < args.length) {
|
||||
var s = args[i++];
|
||||
let s = args[i++];
|
||||
if (s.charCodeAt(0) === CharacterCodes.at) {
|
||||
parseResponseFile(s.slice(1));
|
||||
}
|
||||
@@ -257,7 +257,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (hasProperty(optionNameMap, s)) {
|
||||
var opt = optionNameMap[s];
|
||||
let opt = optionNameMap[s];
|
||||
|
||||
// Check to see if no argument was provided (e.g. "--locale" is the last command-line argument).
|
||||
if (!args[i] && opt.type !== "boolean") {
|
||||
@@ -276,8 +276,8 @@ namespace ts {
|
||||
break;
|
||||
// If not a primitive, the possible types are specified in what is effectively a map of options.
|
||||
default:
|
||||
var map = <Map<number>>opt.type;
|
||||
var key = (args[i++] || "").toLowerCase();
|
||||
let map = <Map<number>>opt.type;
|
||||
let key = (args[i++] || "").toLowerCase();
|
||||
if (hasProperty(map, key)) {
|
||||
options[opt.name] = map[key];
|
||||
}
|
||||
@@ -297,19 +297,19 @@ namespace ts {
|
||||
}
|
||||
|
||||
function parseResponseFile(fileName: string) {
|
||||
var text = sys.readFile(fileName);
|
||||
let text = sys.readFile(fileName);
|
||||
|
||||
if (!text) {
|
||||
errors.push(createCompilerDiagnostic(Diagnostics.File_0_not_found, fileName));
|
||||
return;
|
||||
}
|
||||
|
||||
var args: string[] = [];
|
||||
var pos = 0;
|
||||
let args: string[] = [];
|
||||
let pos = 0;
|
||||
while (true) {
|
||||
while (pos < text.length && text.charCodeAt(pos) <= CharacterCodes.space) pos++;
|
||||
if (pos >= text.length) break;
|
||||
var start = pos;
|
||||
let start = pos;
|
||||
if (text.charCodeAt(start) === CharacterCodes.doubleQuote) {
|
||||
pos++;
|
||||
while (pos < text.length && text.charCodeAt(pos) !== CharacterCodes.doubleQuote) pos++;
|
||||
@@ -335,8 +335,9 @@ namespace ts {
|
||||
* @param fileName The path to the config file
|
||||
*/
|
||||
export function readConfigFile(fileName: string): { config?: any; error?: Diagnostic } {
|
||||
let text = '';
|
||||
try {
|
||||
var text = sys.readFile(fileName);
|
||||
text = sys.readFile(fileName);
|
||||
}
|
||||
catch (e) {
|
||||
return { error: createCompilerDiagnostic(Diagnostics.Cannot_read_file_0_Colon_1, fileName, e.message) };
|
||||
@@ -362,10 +363,10 @@ namespace ts {
|
||||
* Parse the contents of a config file (tsconfig.json).
|
||||
* @param json The contents of the config file to parse
|
||||
* @param basePath A root directory to resolve relative path entries in the config
|
||||
* file to. e.g. outDir
|
||||
* file to. e.g. outDir
|
||||
*/
|
||||
export function parseConfigFile(json: any, host: ParseConfigHost, basePath: string): ParsedCommandLine {
|
||||
var errors: Diagnostic[] = [];
|
||||
let errors: Diagnostic[] = [];
|
||||
|
||||
return {
|
||||
options: getCompilerOptions(),
|
||||
@@ -374,22 +375,22 @@ namespace ts {
|
||||
};
|
||||
|
||||
function getCompilerOptions(): CompilerOptions {
|
||||
var options: CompilerOptions = {};
|
||||
var optionNameMap: Map<CommandLineOption> = {};
|
||||
let options: CompilerOptions = {};
|
||||
let optionNameMap: Map<CommandLineOption> = {};
|
||||
forEach(optionDeclarations, option => {
|
||||
optionNameMap[option.name] = option;
|
||||
});
|
||||
var jsonOptions = json["compilerOptions"];
|
||||
let jsonOptions = json["compilerOptions"];
|
||||
if (jsonOptions) {
|
||||
for (var id in jsonOptions) {
|
||||
for (let id in jsonOptions) {
|
||||
if (hasProperty(optionNameMap, id)) {
|
||||
var opt = optionNameMap[id];
|
||||
var optType = opt.type;
|
||||
var value = jsonOptions[id];
|
||||
var expectedType = typeof optType === "string" ? optType : "string";
|
||||
let opt = optionNameMap[id];
|
||||
let optType = opt.type;
|
||||
let value = jsonOptions[id];
|
||||
let expectedType = typeof optType === "string" ? optType : "string";
|
||||
if (typeof value === expectedType) {
|
||||
if (typeof optType !== "string") {
|
||||
var key = value.toLowerCase();
|
||||
let key = value.toLowerCase();
|
||||
if (hasProperty(optType, key)) {
|
||||
value = optType[key];
|
||||
}
|
||||
@@ -424,7 +425,7 @@ namespace ts {
|
||||
}
|
||||
else {
|
||||
let exclude = json["exclude"] instanceof Array ? map(<string[]>json["exclude"], normalizeSlashes) : undefined;
|
||||
let sysFiles = host.readDirectory(basePath, ".ts", exclude).concat(host.readDirectory(basePath, ".tsx", exclude));
|
||||
let sysFiles = host.readDirectory(basePath, ".ts", exclude).concat(host.readDirectory(basePath, ".tsx", exclude));
|
||||
for (let i = 0; i < sysFiles.length; i++) {
|
||||
let name = sysFiles[i];
|
||||
if (fileExtensionIs(name, ".d.ts")) {
|
||||
@@ -435,7 +436,7 @@ namespace ts {
|
||||
}
|
||||
else if (fileExtensionIs(name, ".ts")) {
|
||||
if (!contains(sysFiles, name + "x")) {
|
||||
fileNames.push(name)
|
||||
fileNames.push(name);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace ts {
|
||||
contains,
|
||||
remove,
|
||||
forEachValue: forEachValueInMap
|
||||
}
|
||||
};
|
||||
|
||||
function set(fileName: string, value: T) {
|
||||
files[normalizeKey(fileName)] = value;
|
||||
@@ -170,7 +170,7 @@ namespace ts {
|
||||
to.push(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function rangeEquals<T>(array1: T[], array2: T[], pos: number, end: number) {
|
||||
while (pos < end) {
|
||||
@@ -372,7 +372,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
let text = getLocaleSpecificMessage(message.key);
|
||||
|
||||
|
||||
if (arguments.length > 4) {
|
||||
text = formatStringFromArgs(text, arguments, 4);
|
||||
}
|
||||
@@ -542,7 +542,7 @@ namespace ts {
|
||||
else {
|
||||
// A part may be an empty string (which is 'falsy') if the path had consecutive slashes,
|
||||
// e.g. "path//file.ts". Drop these before re-joining the parts.
|
||||
if(part) {
|
||||
if (part) {
|
||||
normalized.push(part);
|
||||
}
|
||||
}
|
||||
@@ -600,20 +600,20 @@ namespace ts {
|
||||
|
||||
function getNormalizedPathComponentsOfUrl(url: string) {
|
||||
// Get root length of http://www.website.com/folder1/foler2/
|
||||
// In this example the root is: http://www.website.com/
|
||||
// In this example the root is: http://www.website.com/
|
||||
// normalized path components should be ["http://www.website.com/", "folder1", "folder2"]
|
||||
|
||||
let urlLength = url.length;
|
||||
// Initial root length is http:// part
|
||||
let rootLength = url.indexOf("://") + "://".length;
|
||||
while (rootLength < urlLength) {
|
||||
// Consume all immediate slashes in the protocol
|
||||
// Consume all immediate slashes in the protocol
|
||||
// eg.initial rootlength is just file:// but it needs to consume another "/" in file:///
|
||||
if (url.charCodeAt(rootLength) === CharacterCodes.slash) {
|
||||
rootLength++;
|
||||
}
|
||||
else {
|
||||
// non slash character means we continue proceeding to next component of root search
|
||||
// non slash character means we continue proceeding to next component of root search
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -626,15 +626,15 @@ namespace ts {
|
||||
// Find the index of "/" after website.com so the root can be http://www.website.com/ (from existing http://)
|
||||
let indexOfNextSlash = url.indexOf(directorySeparator, rootLength);
|
||||
if (indexOfNextSlash !== -1) {
|
||||
// Found the "/" after the website.com so the root is length of http://www.website.com/
|
||||
// Found the "/" after the website.com so the root is length of http://www.website.com/
|
||||
// and get components afetr the root normally like any other folder components
|
||||
rootLength = indexOfNextSlash + 1;
|
||||
return normalizedPathComponents(url, rootLength);
|
||||
}
|
||||
else {
|
||||
// Can't find the host assume the rest of the string as component
|
||||
// Can't find the host assume the rest of the string as component
|
||||
// but make sure we append "/" to it as root is not joined using "/"
|
||||
// eg. if url passed in was http://website.com we want to use root as [http://website.com/]
|
||||
// eg. if url passed in was http://website.com we want to use root as [http://website.com/]
|
||||
// so that other path manipulations will be correct and it can be merged with relative paths correctly
|
||||
return [url + directorySeparator];
|
||||
}
|
||||
@@ -774,7 +774,7 @@ namespace ts {
|
||||
getSymbolConstructor: () => <any>Symbol,
|
||||
getTypeConstructor: () => <any>Type,
|
||||
getSignatureConstructor: () => <any>Signature
|
||||
}
|
||||
};
|
||||
|
||||
export const enum AssertionLevel {
|
||||
None = 0,
|
||||
|
||||
@@ -130,7 +130,7 @@ namespace ts {
|
||||
moduleElementDeclarationEmitInfo,
|
||||
synchronousDeclarationOutput: writer.getText(),
|
||||
referencePathsOutput,
|
||||
}
|
||||
};
|
||||
|
||||
function hasInternalAnnotation(range: CommentRange) {
|
||||
let text = currentSourceFile.text;
|
||||
@@ -188,7 +188,7 @@ namespace ts {
|
||||
if (!moduleElementEmitInfo && asynchronousSubModuleDeclarationEmitInfo) {
|
||||
moduleElementEmitInfo = forEach(asynchronousSubModuleDeclarationEmitInfo, declEmitInfo => declEmitInfo.node === nodeToCheck ? declEmitInfo : undefined);
|
||||
}
|
||||
|
||||
|
||||
// If the alias was marked as not visible when we saw its declaration, we would have saved the aliasEmitInfo, but if we haven't yet visited the alias declaration
|
||||
// then we don't need to write it at this point. We will write it when we actually see its declaration
|
||||
// Eg.
|
||||
@@ -198,7 +198,7 @@ namespace ts {
|
||||
// we would write alias foo declaration when we visit it since it would now be marked as visible
|
||||
if (moduleElementEmitInfo) {
|
||||
if (moduleElementEmitInfo.node.kind === SyntaxKind.ImportDeclaration) {
|
||||
// we have to create asynchronous output only after we have collected complete information
|
||||
// we have to create asynchronous output only after we have collected complete information
|
||||
// because it is possible to enable multiple bindings as asynchronously visible
|
||||
moduleElementEmitInfo.isVisible = true;
|
||||
}
|
||||
@@ -353,6 +353,21 @@ namespace ts {
|
||||
return emitEntityName(<Identifier>type);
|
||||
case SyntaxKind.QualifiedName:
|
||||
return emitEntityName(<QualifiedName>type);
|
||||
case SyntaxKind.TypePredicate:
|
||||
return emitTypePredicate(<TypePredicateNode>type);
|
||||
}
|
||||
|
||||
function writeEntityName(entityName: EntityName | Expression) {
|
||||
if (entityName.kind === SyntaxKind.Identifier) {
|
||||
writeTextOfNode(currentSourceFile, entityName);
|
||||
}
|
||||
else {
|
||||
let left = entityName.kind === SyntaxKind.QualifiedName ? (<QualifiedName>entityName).left : (<PropertyAccessExpression>entityName).expression;
|
||||
let right = entityName.kind === SyntaxKind.QualifiedName ? (<QualifiedName>entityName).right : (<PropertyAccessExpression>entityName).name;
|
||||
writeEntityName(left);
|
||||
write(".");
|
||||
writeTextOfNode(currentSourceFile, right);
|
||||
}
|
||||
}
|
||||
|
||||
function emitEntityName(entityName: EntityName | PropertyAccessExpression) {
|
||||
@@ -362,19 +377,6 @@ namespace ts {
|
||||
|
||||
handleSymbolAccessibilityError(visibilityResult);
|
||||
writeEntityName(entityName);
|
||||
|
||||
function writeEntityName(entityName: EntityName | Expression) {
|
||||
if (entityName.kind === SyntaxKind.Identifier) {
|
||||
writeTextOfNode(currentSourceFile, entityName);
|
||||
}
|
||||
else {
|
||||
let left = entityName.kind === SyntaxKind.QualifiedName ? (<QualifiedName>entityName).left : (<PropertyAccessExpression>entityName).expression;
|
||||
let right = entityName.kind === SyntaxKind.QualifiedName ? (<QualifiedName>entityName).right : (<PropertyAccessExpression>entityName).name;
|
||||
writeEntityName(left);
|
||||
write(".");
|
||||
writeTextOfNode(currentSourceFile, right);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function emitExpressionWithTypeArguments(node: ExpressionWithTypeArguments) {
|
||||
@@ -398,6 +400,12 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function emitTypePredicate(type: TypePredicateNode) {
|
||||
writeTextOfNode(currentSourceFile, type.parameterName);
|
||||
write(" is ");
|
||||
emitType(type.type);
|
||||
}
|
||||
|
||||
function emitTypeQuery(type: TypeQueryNode) {
|
||||
write("typeof ");
|
||||
emitEntityName(type.exprName);
|
||||
@@ -600,7 +608,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function writeImportEqualsDeclaration(node: ImportEqualsDeclaration) {
|
||||
// note usage of writer. methods instead of aliases created, just to make sure we are using
|
||||
// note usage of writer. methods instead of aliases created, just to make sure we are using
|
||||
// correct writer especially to handle asynchronous alias writing
|
||||
emitJsDocComments(node);
|
||||
if (node.flags & NodeFlags.Export) {
|
||||
@@ -642,7 +650,7 @@ namespace ts {
|
||||
|
||||
function writeImportDeclaration(node: ImportDeclaration) {
|
||||
if (!node.importClause && !(node.flags & NodeFlags.Export)) {
|
||||
// do not write non-exported import declarations that don't have import clauses
|
||||
// do not write non-exported import declarations that don't have import clauses
|
||||
return;
|
||||
}
|
||||
emitJsDocComments(node);
|
||||
@@ -764,7 +772,7 @@ namespace ts {
|
||||
emitJsDocComments(node);
|
||||
emitModuleElementDeclarationFlags(node);
|
||||
if (isConst(node)) {
|
||||
write("const ")
|
||||
write("const ");
|
||||
}
|
||||
write("enum ");
|
||||
writeTextOfNode(currentSourceFile, node.name);
|
||||
@@ -1343,7 +1351,7 @@ namespace ts {
|
||||
|
||||
return {
|
||||
diagnosticMessage,
|
||||
errorNode: <Node>node.name || node,
|
||||
errorNode: <Node>node.name || node
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1517,7 +1525,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function emitNode(node: Node) {
|
||||
@@ -1565,7 +1573,7 @@ namespace ts {
|
||||
? referencedFile.fileName // Declaration file, use declaration file name
|
||||
: shouldEmitToOwnFile(referencedFile, compilerOptions)
|
||||
? getOwnEmitOutputFilePath(referencedFile, host, ".d.ts") // Own output file so get the .d.ts file
|
||||
: removeFileExtension(compilerOptions.out) + ".d.ts";// Global out file
|
||||
: removeFileExtension(compilerOptions.out) + ".d.ts"; // Global out file
|
||||
|
||||
declFileName = getRelativePathToDirectoryOrUrl(
|
||||
getDirectoryPath(normalizeSlashes(jsFilePath)),
|
||||
@@ -1577,7 +1585,7 @@ namespace ts {
|
||||
referencePathsOutput += "/// <reference path=\"" + declFileName + "\" />" + newLine;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* @internal */
|
||||
export function writeDeclarationFile(jsFilePath: string, sourceFile: SourceFile, host: EmitHost, resolver: EmitResolver, diagnostics: Diagnostic[]) {
|
||||
let emitDeclarationResult = emitDeclarations(host, resolver, diagnostics, jsFilePath, sourceFile);
|
||||
@@ -1604,4 +1612,4 @@ namespace ts {
|
||||
return declarationOutput;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,7 +407,7 @@ namespace ts {
|
||||
Classes_containing_abstract_methods_must_be_marked_abstract: { code: 2514, category: DiagnosticCategory.Error, key: "Classes containing abstract methods must be marked abstract." },
|
||||
Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_from_class_2: { code: 2515, category: DiagnosticCategory.Error, key: "Non-abstract class '{0}' does not implement inherited abstract member '{1}' from class '{2}'." },
|
||||
All_declarations_of_an_abstract_method_must_be_consecutive: { code: 2516, category: DiagnosticCategory.Error, key: "All declarations of an abstract method must be consecutive." },
|
||||
Constructor_objects_of_abstract_type_cannot_be_assigned_to_constructor_objects_of_non_abstract_type: { code: 2517, category: DiagnosticCategory.Error, key: "Constructor objects of abstract type cannot be assigned to constructor objects of non-abstract type" },
|
||||
Cannot_assign_an_abstract_constructor_type_to_a_non_abstract_constructor_type: { code: 2517, category: DiagnosticCategory.Error, key: "Cannot assign an abstract constructor type to a non-abstract constructor type." },
|
||||
Only_an_ambient_class_can_be_merged_with_an_interface: { code: 2518, category: DiagnosticCategory.Error, key: "Only an ambient class can be merged with an interface." },
|
||||
Duplicate_identifier_0_Compiler_uses_declaration_1_to_support_async_functions: { code: 2520, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler uses declaration '{1}' to support async functions." },
|
||||
Expression_resolves_to_variable_declaration_0_that_compiler_uses_to_support_async_functions: { code: 2521, category: DiagnosticCategory.Error, key: "Expression resolves to variable declaration '{0}' that compiler uses to support async functions." },
|
||||
|
||||
@@ -1617,7 +1617,7 @@
|
||||
"category": "Error",
|
||||
"code": 2516
|
||||
},
|
||||
"Constructor objects of abstract type cannot be assigned to constructor objects of non-abstract type": {
|
||||
"Cannot assign an abstract constructor type to a non-abstract constructor type.": {
|
||||
"category": "Error",
|
||||
"code":2517
|
||||
},
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -410,7 +410,7 @@ namespace ts {
|
||||
export function updateSourceFile(sourceFile: SourceFile, newText: string, textChangeRange: TextChangeRange, aggressiveChecks?: boolean): SourceFile {
|
||||
return IncrementalParser.updateSourceFile(sourceFile, newText, textChangeRange, aggressiveChecks);
|
||||
}
|
||||
|
||||
|
||||
/* @internal */
|
||||
export function parseIsolatedJSDocComment(content: string, start?: number, length?: number) {
|
||||
return Parser.JSDocParser.parseIsolatedJSDocComment(content, start, length);
|
||||
@@ -585,7 +585,7 @@ namespace ts {
|
||||
fixupParentReferences(sourceFile);
|
||||
}
|
||||
|
||||
// If this is a javascript file, proactively see if we can get JSDoc comments for
|
||||
// If this is a javascript file, proactively see if we can get JSDoc comments for
|
||||
// relevant nodes in the file. We'll use these to provide typing informaion if they're
|
||||
// available.
|
||||
if (isJavaScript(fileName)) {
|
||||
@@ -685,17 +685,17 @@ namespace ts {
|
||||
function setDecoratorContext(val: boolean) {
|
||||
setContextFlag(val, ParserContextFlags.Decorator);
|
||||
}
|
||||
|
||||
|
||||
function setAwaitContext(val: boolean) {
|
||||
setContextFlag(val, ParserContextFlags.Await);
|
||||
}
|
||||
|
||||
|
||||
function doOutsideOfContext<T>(context: ParserContextFlags, func: () => T): T {
|
||||
// contextFlagsToClear will contain only the context flags that are
|
||||
// contextFlagsToClear will contain only the context flags that are
|
||||
// currently set that we need to temporarily clear
|
||||
// We don't just blindly reset to the previous flags to ensure
|
||||
// that we do not mutate cached flags for the incremental
|
||||
// parser (ThisNodeHasError, ThisNodeOrAnySubNodesHasError, and
|
||||
// parser (ThisNodeHasError, ThisNodeOrAnySubNodesHasError, and
|
||||
// HasAggregatedChildData).
|
||||
let contextFlagsToClear = context & contextFlags;
|
||||
if (contextFlagsToClear) {
|
||||
@@ -710,13 +710,13 @@ namespace ts {
|
||||
// no need to do anything special as we are not in any of the requested contexts
|
||||
return func();
|
||||
}
|
||||
|
||||
|
||||
function doInsideOfContext<T>(context: ParserContextFlags, func: () => T): T {
|
||||
// contextFlagsToSet will contain only the context flags that
|
||||
// are not currently set that we need to temporarily enable.
|
||||
// We don't just blindly reset to the previous flags to ensure
|
||||
// that we do not mutate cached flags for the incremental
|
||||
// parser (ThisNodeHasError, ThisNodeOrAnySubNodesHasError, and
|
||||
// parser (ThisNodeHasError, ThisNodeOrAnySubNodesHasError, and
|
||||
// HasAggregatedChildData).
|
||||
let contextFlagsToSet = context & ~contextFlags;
|
||||
if (contextFlagsToSet) {
|
||||
@@ -727,11 +727,11 @@ namespace ts {
|
||||
setContextFlag(false, contextFlagsToSet);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
// no need to do anything special as we are already in all of the requested contexts
|
||||
return func();
|
||||
}
|
||||
|
||||
|
||||
function allowInAnd<T>(func: () => T): T {
|
||||
return doOutsideOfContext(ParserContextFlags.DisallowIn, func);
|
||||
}
|
||||
@@ -739,7 +739,7 @@ namespace ts {
|
||||
function disallowInAnd<T>(func: () => T): T {
|
||||
return doInsideOfContext(ParserContextFlags.DisallowIn, func);
|
||||
}
|
||||
|
||||
|
||||
function doInYieldContext<T>(func: () => T): T {
|
||||
return doInsideOfContext(ParserContextFlags.Yield, func);
|
||||
}
|
||||
@@ -751,23 +751,23 @@ namespace ts {
|
||||
function doInDecoratorContext<T>(func: () => T): T {
|
||||
return doInsideOfContext(ParserContextFlags.Decorator, func);
|
||||
}
|
||||
|
||||
|
||||
function doInAwaitContext<T>(func: () => T): T {
|
||||
return doInsideOfContext(ParserContextFlags.Await, func);
|
||||
}
|
||||
|
||||
|
||||
function doOutsideOfAwaitContext<T>(func: () => T): T {
|
||||
return doOutsideOfContext(ParserContextFlags.Await, func);
|
||||
}
|
||||
|
||||
|
||||
function doInYieldAndAwaitContext<T>(func: () => T): T {
|
||||
return doInsideOfContext(ParserContextFlags.Yield | ParserContextFlags.Await, func);
|
||||
}
|
||||
|
||||
|
||||
function doOutsideOfYieldAndAwaitContext<T>(func: () => T): T {
|
||||
return doOutsideOfContext(ParserContextFlags.Yield | ParserContextFlags.Await, func);
|
||||
}
|
||||
|
||||
|
||||
function inContext(flags: ParserContextFlags) {
|
||||
return (contextFlags & flags) !== 0;
|
||||
}
|
||||
@@ -787,7 +787,7 @@ namespace ts {
|
||||
function inAwaitContext() {
|
||||
return inContext(ParserContextFlags.Await);
|
||||
}
|
||||
|
||||
|
||||
function parseErrorAtCurrentToken(message: DiagnosticMessage, arg0?: any): void {
|
||||
let start = scanner.getTokenPos();
|
||||
let length = scanner.getTextPos() - start;
|
||||
@@ -843,7 +843,7 @@ namespace ts {
|
||||
function scanJsxIdentifier(): SyntaxKind {
|
||||
return token = scanner.scanJsxIdentifier();
|
||||
}
|
||||
|
||||
|
||||
function speculationHelper<T>(callback: () => T, isLookAhead: boolean): T {
|
||||
// Keep track of the state we'll need to rollback to if lookahead fails (or if the
|
||||
// caller asked us to always reset our state).
|
||||
@@ -903,7 +903,7 @@ namespace ts {
|
||||
if (token === SyntaxKind.YieldKeyword && inYieldContext()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// If we have a 'await' keyword, and we're in the [Await] context, then 'await' is
|
||||
// considered a keyword and is not an identifier.
|
||||
if (token === SyntaxKind.AwaitKeyword && inAwaitContext()) {
|
||||
@@ -1102,7 +1102,7 @@ namespace ts {
|
||||
function parseContextualModifier(t: SyntaxKind): boolean {
|
||||
return token === t && tryParse(nextTokenCanFollowModifier);
|
||||
}
|
||||
|
||||
|
||||
function nextTokenCanFollowModifier() {
|
||||
if (token === SyntaxKind.ConstKeyword) {
|
||||
// 'const' is only a modifier if followed by 'enum'.
|
||||
@@ -1121,7 +1121,7 @@ namespace ts {
|
||||
nextToken();
|
||||
return canFollowModifier();
|
||||
}
|
||||
|
||||
|
||||
function parseAnyContextualModifier(): boolean {
|
||||
return isModifier(token) && tryParse(nextTokenCanFollowModifier);
|
||||
}
|
||||
@@ -1229,7 +1229,7 @@ namespace ts {
|
||||
// if we see "extends {}" then only treat the {} as what we're extending (and not
|
||||
// the class body) if we have:
|
||||
//
|
||||
// extends {} {
|
||||
// extends {} {
|
||||
// extends {},
|
||||
// extends {} extends
|
||||
// extends {} implements
|
||||
@@ -1844,7 +1844,7 @@ namespace ts {
|
||||
do {
|
||||
templateSpans.push(parseTemplateSpan());
|
||||
}
|
||||
while (lastOrUndefined(templateSpans).literal.kind === SyntaxKind.TemplateMiddle)
|
||||
while (lastOrUndefined(templateSpans).literal.kind === SyntaxKind.TemplateMiddle);
|
||||
|
||||
templateSpans.end = getNodeEnd();
|
||||
template.templateSpans = templateSpans;
|
||||
@@ -1859,7 +1859,7 @@ namespace ts {
|
||||
let literal: LiteralExpression;
|
||||
|
||||
if (token === SyntaxKind.CloseBraceToken) {
|
||||
reScanTemplateToken()
|
||||
reScanTemplateToken();
|
||||
literal = parseLiteralNode();
|
||||
}
|
||||
else {
|
||||
@@ -2019,7 +2019,7 @@ namespace ts {
|
||||
// ambient contexts.
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
|
||||
function parseBindingElementInitializer(inParameter: boolean) {
|
||||
return inParameter ? parseParameterInitializer() : parseNonParameterInitializer();
|
||||
}
|
||||
@@ -2027,7 +2027,7 @@ namespace ts {
|
||||
function parseParameterInitializer() {
|
||||
return parseInitializer(/*inParameter*/ true);
|
||||
}
|
||||
|
||||
|
||||
function fillSignature(
|
||||
returnToken: SyntaxKind,
|
||||
yieldContext: boolean,
|
||||
@@ -2065,15 +2065,15 @@ namespace ts {
|
||||
if (parseExpected(SyntaxKind.OpenParenToken)) {
|
||||
let savedYieldContext = inYieldContext();
|
||||
let savedAwaitContext = inAwaitContext();
|
||||
|
||||
|
||||
setYieldContext(yieldContext);
|
||||
setAwaitContext(awaitContext);
|
||||
|
||||
|
||||
let result = parseDelimitedList(ParsingContext.Parameters, parseParameter);
|
||||
|
||||
|
||||
setYieldContext(savedYieldContext);
|
||||
setAwaitContext(savedAwaitContext);
|
||||
|
||||
|
||||
if (!parseExpected(SyntaxKind.CloseParenToken) && requireCompleteParameterList) {
|
||||
// Caller insisted that we had to end with a ) We didn't. So just return
|
||||
// undefined here.
|
||||
@@ -2088,7 +2088,7 @@ namespace ts {
|
||||
// then just return an empty set of parameters.
|
||||
return requireCompleteParameterList ? undefined : createMissingList<ParameterDeclaration>();
|
||||
}
|
||||
|
||||
|
||||
function parseTypeMemberSemicolon() {
|
||||
// We allow type members to be separated by commas or (possibly ASI) semicolons.
|
||||
// First check if it was a comma. If so, we're done with the member.
|
||||
@@ -2180,7 +2180,7 @@ namespace ts {
|
||||
node.parameters = parseBracketedList(ParsingContext.Parameters, parseParameter, SyntaxKind.OpenBracketToken, SyntaxKind.CloseBracketToken);
|
||||
node.type = parseTypeAnnotation();
|
||||
parseTypeMemberSemicolon();
|
||||
return finishNode(node)
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
function parsePropertyOrMethodSignature(): Declaration {
|
||||
@@ -2471,7 +2471,7 @@ namespace ts {
|
||||
|
||||
function parseType(): TypeNode {
|
||||
// The rules about 'yield' only apply to actual code/expression contexts. They don't
|
||||
// apply to 'type' contexts. So we disable these parameters here before moving on.
|
||||
// apply to 'type' contexts. So we disable these parameters here before moving on.
|
||||
return doOutsideOfContext(ParserContextFlags.TypeExcludesFlags, parseTypeWorker);
|
||||
}
|
||||
|
||||
@@ -2559,7 +2559,7 @@ namespace ts {
|
||||
token !== SyntaxKind.AtToken &&
|
||||
isStartOfExpression();
|
||||
}
|
||||
|
||||
|
||||
function allowInAndParseExpression(): Expression {
|
||||
return allowInAnd(parseExpression);
|
||||
}
|
||||
@@ -2748,7 +2748,7 @@ namespace ts {
|
||||
// It's definitely not a parenthesized arrow function expression.
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
// If we definitely have an arrow function, then we can just parse one, not requiring a
|
||||
// following => or { token. Otherwise, we *might* have an arrow function. Try to parse
|
||||
// it out, but don't allow any ambiguity, and return 'undefined' if this could be an
|
||||
@@ -2761,12 +2761,12 @@ namespace ts {
|
||||
// Didn't appear to actually be a parenthesized arrow function. Just bail out.
|
||||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
let isAsync = !!(arrowFunction.flags & NodeFlags.Async);
|
||||
|
||||
// If we have an arrow, then try to parse the body. Even if not, try to parse if we
|
||||
// have an opening brace, just in case we're in an error state.
|
||||
var lastToken = token;
|
||||
let lastToken = token;
|
||||
arrowFunction.equalsGreaterThanToken = parseExpectedToken(SyntaxKind.EqualsGreaterThanToken, /*reportAtCurrentPosition*/false, Diagnostics._0_expected, "=>");
|
||||
arrowFunction.body = (lastToken === SyntaxKind.EqualsGreaterThanToken || lastToken === SyntaxKind.OpenBraceToken)
|
||||
? parseArrowFunctionExpressionBody(isAsync)
|
||||
@@ -2804,7 +2804,7 @@ namespace ts {
|
||||
return Tristate.False;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let first = token;
|
||||
let second = nextToken();
|
||||
|
||||
@@ -2892,7 +2892,7 @@ namespace ts {
|
||||
if (isArrowFunctionInJsx) {
|
||||
return Tristate.True;
|
||||
}
|
||||
|
||||
|
||||
return Tristate.False;
|
||||
}
|
||||
|
||||
@@ -2909,7 +2909,7 @@ namespace ts {
|
||||
let node = <ArrowFunction>createNode(SyntaxKind.ArrowFunction);
|
||||
setModifiers(node, parseModifiersForArrowFunction());
|
||||
let isAsync = !!(node.flags & NodeFlags.Async);
|
||||
|
||||
|
||||
// Arrow functions are never generators.
|
||||
//
|
||||
// If we're speculatively parsing a signature for a parenthesized arrow function, then
|
||||
@@ -2966,7 +2966,7 @@ namespace ts {
|
||||
// Note: even when 'ignoreMissingOpenBrace' is passed as true, parseBody will still error.
|
||||
return parseFunctionBlock(/*allowYield*/ false, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ true);
|
||||
}
|
||||
|
||||
|
||||
return isAsync
|
||||
? doInAwaitContext(parseAssignmentExpressionOrHigher)
|
||||
: doOutsideOfAwaitContext(parseAssignmentExpressionOrHigher);
|
||||
@@ -3133,7 +3133,7 @@ namespace ts {
|
||||
node.expression = parseUnaryExpressionOrHigher();
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
|
||||
function isAwaitExpression(): boolean {
|
||||
if (token === SyntaxKind.AwaitKeyword) {
|
||||
if (inAwaitContext()) {
|
||||
@@ -3158,7 +3158,7 @@ namespace ts {
|
||||
if (isAwaitExpression()) {
|
||||
return parseAwaitExpression();
|
||||
}
|
||||
|
||||
|
||||
switch (token) {
|
||||
case SyntaxKind.PlusToken:
|
||||
case SyntaxKind.MinusToken:
|
||||
@@ -3177,7 +3177,7 @@ namespace ts {
|
||||
if (sourceFile.languageVariant !== LanguageVariant.JSX) {
|
||||
return parseTypeAssertion();
|
||||
}
|
||||
if(lookAhead(nextTokenIsIdentifierOrKeyword)) {
|
||||
if (lookAhead(nextTokenIsIdentifierOrKeyword)) {
|
||||
return parseJsxElementOrSelfClosingElement();
|
||||
}
|
||||
// Fall through
|
||||
@@ -3295,7 +3295,7 @@ namespace ts {
|
||||
|
||||
function parseSuperExpression(): MemberExpression {
|
||||
let expression = parseTokenNode<PrimaryExpression>();
|
||||
if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.DotToken) {
|
||||
if (token === SyntaxKind.OpenParenToken || token === SyntaxKind.DotToken || token === SyntaxKind.OpenBracketToken) {
|
||||
return expression;
|
||||
}
|
||||
|
||||
@@ -3307,7 +3307,7 @@ namespace ts {
|
||||
node.name = parseRightSideOfDot(/*allowIdentifierNames*/ true);
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
|
||||
function parseJsxElementOrSelfClosingElement(): JsxElement|JsxSelfClosingElement {
|
||||
let opening = parseJsxOpeningOrSelfClosingElement();
|
||||
if (opening.kind === SyntaxKind.JsxOpeningElement) {
|
||||
@@ -3349,7 +3349,7 @@ namespace ts {
|
||||
let saveParsingContext = parsingContext;
|
||||
parsingContext |= 1 << ParsingContext.JsxChildren;
|
||||
|
||||
while(true) {
|
||||
while (true) {
|
||||
token = scanner.reScanJsxToken();
|
||||
if (token === SyntaxKind.LessThanSlashToken) {
|
||||
break;
|
||||
@@ -3367,7 +3367,7 @@ namespace ts {
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
function parseJsxOpeningOrSelfClosingElement(): JsxOpeningElement|JsxSelfClosingElement {
|
||||
let fullStart = scanner.getStartPos();
|
||||
|
||||
@@ -3392,7 +3392,7 @@ namespace ts {
|
||||
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
|
||||
function parseJsxElementName(): EntityName {
|
||||
scanJsxIdentifier();
|
||||
let elementName: EntityName = parseIdentifierName();
|
||||
@@ -3477,7 +3477,7 @@ namespace ts {
|
||||
continue;
|
||||
}
|
||||
|
||||
// when in the [Decorator] context, we do not parse ElementAccess as it could be part of a ComputedPropertyName
|
||||
// when in the [Decorator] context, we do not parse ElementAccess as it could be part of a ComputedPropertyName
|
||||
if (!inDecoratorContext() && parseOptional(SyntaxKind.OpenBracketToken)) {
|
||||
let indexedAccess = <ElementAccessExpression>createNode(SyntaxKind.ElementAccessExpression, expression.pos);
|
||||
indexedAccess.expression = expression;
|
||||
@@ -3599,7 +3599,7 @@ namespace ts {
|
||||
case SyntaxKind.CommaToken: // foo<x>,
|
||||
case SyntaxKind.OpenBraceToken: // foo<x> {
|
||||
// We don't want to treat these as type arguments. Otherwise we'll parse this
|
||||
// as an invocation expression. Instead, we want to parse out the expression
|
||||
// as an invocation expression. Instead, we want to parse out the expression
|
||||
// in isolation from the type arguments.
|
||||
|
||||
default:
|
||||
@@ -3627,7 +3627,7 @@ namespace ts {
|
||||
case SyntaxKind.OpenBraceToken:
|
||||
return parseObjectLiteralExpression();
|
||||
case SyntaxKind.AsyncKeyword:
|
||||
// Async arrow functions are parsed earlier in parseAssignmentExpressionOrHigher.
|
||||
// Async arrow functions are parsed earlier in parseAssignmentExpressionOrHigher.
|
||||
// If we encounter `async [no LineTerminator here] function` then this is an async
|
||||
// function; otherwise, its an identifier.
|
||||
if (!lookAhead(nextTokenIsFunctionKeywordOnSameLine)) {
|
||||
@@ -3759,12 +3759,12 @@ namespace ts {
|
||||
if (saveDecoratorContext) {
|
||||
setDecoratorContext(false);
|
||||
}
|
||||
|
||||
|
||||
let node = <FunctionExpression>createNode(SyntaxKind.FunctionExpression);
|
||||
setModifiers(node, parseModifiers());
|
||||
parseExpected(SyntaxKind.FunctionKeyword);
|
||||
node.asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken);
|
||||
|
||||
|
||||
let isGenerator = !!node.asteriskToken;
|
||||
let isAsync = !!(node.flags & NodeFlags.Async);
|
||||
node.name =
|
||||
@@ -3772,14 +3772,14 @@ namespace ts {
|
||||
isGenerator ? doInYieldContext(parseOptionalIdentifier) :
|
||||
isAsync ? doInAwaitContext(parseOptionalIdentifier) :
|
||||
parseOptionalIdentifier();
|
||||
|
||||
|
||||
fillSignature(SyntaxKind.ColonToken, /*yieldContext*/ isGenerator, /*awaitContext*/ isAsync, /*requireCompleteParameterList*/ false, node);
|
||||
node.body = parseFunctionBlock(/*allowYield*/ isGenerator, /*allowAwait*/ isAsync, /*ignoreMissingOpenBrace*/ false);
|
||||
|
||||
|
||||
if (saveDecoratorContext) {
|
||||
setDecoratorContext(true);
|
||||
}
|
||||
|
||||
|
||||
return finishNode(node);
|
||||
}
|
||||
|
||||
@@ -3815,11 +3815,11 @@ namespace ts {
|
||||
function parseFunctionBlock(allowYield: boolean, allowAwait: boolean, ignoreMissingOpenBrace: boolean, diagnosticMessage?: DiagnosticMessage): Block {
|
||||
let savedYieldContext = inYieldContext();
|
||||
setYieldContext(allowYield);
|
||||
|
||||
|
||||
let savedAwaitContext = inAwaitContext();
|
||||
setAwaitContext(allowAwait);
|
||||
|
||||
// We may be in a [Decorator] context when parsing a function expression or
|
||||
// We may be in a [Decorator] context when parsing a function expression or
|
||||
// arrow function. The body of the function is not in [Decorator] context.
|
||||
let saveDecoratorContext = inDecoratorContext();
|
||||
if (saveDecoratorContext) {
|
||||
@@ -4081,7 +4081,7 @@ namespace ts {
|
||||
nextToken();
|
||||
return isIdentifierOrKeyword() && !scanner.hasPrecedingLineBreak();
|
||||
}
|
||||
|
||||
|
||||
function nextTokenIsFunctionKeywordOnSameLine() {
|
||||
nextToken();
|
||||
return token === SyntaxKind.FunctionKeyword && !scanner.hasPrecedingLineBreak();
|
||||
@@ -4150,7 +4150,7 @@ namespace ts {
|
||||
return true;
|
||||
}
|
||||
continue;
|
||||
|
||||
|
||||
case SyntaxKind.PublicKeyword:
|
||||
case SyntaxKind.PrivateKeyword:
|
||||
case SyntaxKind.ProtectedKeyword:
|
||||
@@ -4229,7 +4229,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function isLetDeclaration() {
|
||||
// In ES6 'let' always starts a lexical declaration if followed by an identifier or {
|
||||
// In ES6 'let' always starts a lexical declaration if followed by an identifier or {
|
||||
// or [.
|
||||
return lookAhead(nextTokenIsIdentifierOrStartOfDestructuring);
|
||||
}
|
||||
@@ -4335,7 +4335,7 @@ namespace ts {
|
||||
default:
|
||||
if (decorators || modifiers) {
|
||||
// We reached this point because we encountered decorators and/or modifiers and assumed a declaration
|
||||
// would follow. For recovery and error reporting purposes, return an incomplete declaration.
|
||||
// would follow. For recovery and error reporting purposes, return an incomplete declaration.
|
||||
let node = <Statement>createMissingNode(SyntaxKind.MissingDeclaration, /*reportAtCurrentPosition*/ true, Diagnostics.Declaration_expected);
|
||||
node.pos = fullStart;
|
||||
node.decorators = decorators;
|
||||
@@ -4550,7 +4550,7 @@ namespace ts {
|
||||
function parsePropertyOrMethodDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray): ClassElement {
|
||||
let asteriskToken = parseOptionalToken(SyntaxKind.AsteriskToken);
|
||||
let name = parsePropertyName();
|
||||
|
||||
|
||||
// Note: this is not legal as per the grammar. But we allow it in the parser and
|
||||
// report an error in the grammar checker.
|
||||
let questionToken = parseOptionalToken(SyntaxKind.QuestionToken);
|
||||
@@ -4694,7 +4694,7 @@ namespace ts {
|
||||
modifiers = <ModifiersArray>[];
|
||||
modifiers.pos = modifierStart;
|
||||
}
|
||||
|
||||
|
||||
flags |= modifierToFlag(modifierKind);
|
||||
modifiers.push(finishNode(createNode(modifierKind, modifierStart)));
|
||||
}
|
||||
@@ -4719,7 +4719,7 @@ namespace ts {
|
||||
modifiers.flags = flags;
|
||||
modifiers.end = scanner.getStartPos();
|
||||
}
|
||||
|
||||
|
||||
return modifiers;
|
||||
}
|
||||
|
||||
@@ -4779,9 +4779,9 @@ namespace ts {
|
||||
function parseClassDeclaration(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray): ClassDeclaration {
|
||||
return <ClassDeclaration>parseClassDeclarationOrExpression(fullStart, decorators, modifiers, SyntaxKind.ClassDeclaration);
|
||||
}
|
||||
|
||||
|
||||
function parseClassDeclarationOrExpression(fullStart: number, decorators: NodeArray<Decorator>, modifiers: ModifiersArray, kind: SyntaxKind): ClassLikeDeclaration {
|
||||
var node = <ClassLikeDeclaration>createNode(kind, fullStart);
|
||||
let node = <ClassLikeDeclaration>createNode(kind, fullStart);
|
||||
node.decorators = decorators;
|
||||
setModifiers(node, modifiers);
|
||||
parseExpected(SyntaxKind.ClassKeyword);
|
||||
@@ -4791,7 +4791,7 @@ namespace ts {
|
||||
|
||||
if (parseExpected(SyntaxKind.OpenBraceToken)) {
|
||||
// ClassTail[Yield,Await] : (Modified) See 14.5
|
||||
// ClassHeritage[?Yield,?Await]opt { ClassBody[?Yield,?Await]opt }
|
||||
// ClassHeritage[?Yield,?Await]opt { ClassBody[?Yield,?Await]opt }
|
||||
node.members = parseClassMembers();
|
||||
parseExpected(SyntaxKind.CloseBraceToken);
|
||||
}
|
||||
@@ -5008,7 +5008,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function parseImportClause(identifier: Identifier, fullStart: number) {
|
||||
//ImportClause:
|
||||
// ImportClause:
|
||||
// ImportedDefaultBinding
|
||||
// NameSpaceImport
|
||||
// NamedImports
|
||||
@@ -5135,7 +5135,12 @@ namespace ts {
|
||||
}
|
||||
else {
|
||||
node.exportClause = parseNamedImportsOrExports(SyntaxKind.NamedExports);
|
||||
if (parseOptional(SyntaxKind.FromKeyword)) {
|
||||
|
||||
// It is not uncommon to accidentally omit the 'from' keyword. Additionally, in editing scenarios,
|
||||
// the 'from' keyword can be parsed as a named export when the export clause is unterminated (i.e. `export { from "moduleName";`)
|
||||
// If we don't have a 'from' keyword, see if we have a string literal such that ASI won't take effect.
|
||||
if (token === SyntaxKind.FromKeyword || (token === SyntaxKind.StringLiteral && !scanner.hasPrecedingLineBreak())) {
|
||||
parseExpected(SyntaxKind.FromKeyword)
|
||||
node.moduleSpecifier = parseModuleSpecifier();
|
||||
}
|
||||
}
|
||||
@@ -5301,7 +5306,7 @@ namespace ts {
|
||||
/* @internal */
|
||||
export function parseJSDocTypeExpression(start: number, length: number): JSDocTypeExpression {
|
||||
scanner.setText(sourceText, start, length);
|
||||
|
||||
|
||||
// Prime the first token for us to start processing.
|
||||
token = nextToken();
|
||||
|
||||
@@ -5316,15 +5321,15 @@ namespace ts {
|
||||
}
|
||||
|
||||
function parseJSDocTopLevelType(): JSDocType {
|
||||
var type = parseJSDocType();
|
||||
let type = parseJSDocType();
|
||||
if (token === SyntaxKind.BarToken) {
|
||||
var unionType = <JSDocUnionType>createNode(SyntaxKind.JSDocUnionType, type.pos);
|
||||
let unionType = <JSDocUnionType>createNode(SyntaxKind.JSDocUnionType, type.pos);
|
||||
unionType.types = parseJSDocTypeList(type);
|
||||
type = finishNode(unionType);
|
||||
}
|
||||
|
||||
if (token === SyntaxKind.EqualsToken) {
|
||||
var optionalType = <JSDocOptionalType>createNode(SyntaxKind.JSDocOptionalType, type.pos);
|
||||
let optionalType = <JSDocOptionalType>createNode(SyntaxKind.JSDocOptionalType, type.pos);
|
||||
nextToken();
|
||||
optionalType.type = type;
|
||||
type = finishNode(optionalType);
|
||||
@@ -5638,9 +5643,9 @@ namespace ts {
|
||||
|
||||
let tags: NodeArray<JSDocTag>;
|
||||
let pos: number;
|
||||
|
||||
// NOTE(cyrusn): This is essentially a handwritten scanner for JSDocComments. I
|
||||
// considered using an actual Scanner, but this would complicate things. The
|
||||
|
||||
// NOTE(cyrusn): This is essentially a handwritten scanner for JSDocComments. I
|
||||
// considered using an actual Scanner, but this would complicate things. The
|
||||
// scanner would need to know it was in a Doc Comment. Otherwise, it would then
|
||||
// produce comments *inside* the doc comment. In the end it was just easier to
|
||||
// write a simple scanner rather than go that route.
|
||||
@@ -5655,13 +5660,13 @@ namespace ts {
|
||||
let canParseTag = true;
|
||||
let seenAsterisk = true;
|
||||
|
||||
for (pos = start + "/**".length; pos < end;) {
|
||||
for (pos = start + "/**".length; pos < end; ) {
|
||||
let ch = content.charCodeAt(pos);
|
||||
pos++;
|
||||
|
||||
if (ch === CharacterCodes.at && canParseTag) {
|
||||
parseTag();
|
||||
|
||||
|
||||
// Once we parse out a tag, we cannot keep parsing out tags on this line.
|
||||
canParseTag = false;
|
||||
continue;
|
||||
@@ -5927,7 +5932,7 @@ namespace ts {
|
||||
if (sourceFile.statements.length === 0) {
|
||||
// If we don't have any statements in the current source file, then there's no real
|
||||
// way to incrementally parse. So just do a full parse instead.
|
||||
return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setNodeParents*/ true)
|
||||
return Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, /*syntaxCursor*/ undefined, /*setNodeParents*/ true);
|
||||
}
|
||||
|
||||
// Make sure we're not trying to incrementally update a source file more than once. Once
|
||||
@@ -5991,7 +5996,7 @@ namespace ts {
|
||||
// inconsistent tree. Setting the parents on the new tree should be very fast. We
|
||||
// will immediately bail out of walking any subtrees when we can see that their parents
|
||||
// are already correct.
|
||||
let result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /* setParentNode */ true)
|
||||
let result = Parser.parseSourceFile(sourceFile.fileName, newText, sourceFile.languageVersion, syntaxCursor, /* setParentNode */ true);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -6006,8 +6011,9 @@ namespace ts {
|
||||
return;
|
||||
|
||||
function visitNode(node: IncrementalNode) {
|
||||
let text = '';
|
||||
if (aggressiveChecks && shouldCheckNode(node)) {
|
||||
var text = oldText.substring(node.pos, node.end);
|
||||
text = oldText.substring(node.pos, node.end);
|
||||
}
|
||||
|
||||
// Ditch any existing LS children we may have created. This way we can avoid
|
||||
@@ -6357,17 +6363,17 @@ namespace ts {
|
||||
|
||||
interface IncrementalElement extends TextRange {
|
||||
parent?: Node;
|
||||
intersectsChange: boolean
|
||||
intersectsChange: boolean;
|
||||
length?: number;
|
||||
_children: Node[];
|
||||
}
|
||||
|
||||
export interface IncrementalNode extends Node, IncrementalElement {
|
||||
hasBeenIncrementallyParsed: boolean
|
||||
hasBeenIncrementallyParsed: boolean;
|
||||
}
|
||||
|
||||
interface IncrementalNodeArray extends NodeArray<IncrementalNode>, IncrementalElement {
|
||||
length: number
|
||||
length: number;
|
||||
}
|
||||
|
||||
// Allows finding nodes in the source file at a certain position in an efficient manner.
|
||||
|
||||
@@ -11,12 +11,12 @@ namespace ts {
|
||||
export const version = "1.5.3";
|
||||
|
||||
export function findConfigFile(searchPath: string): string {
|
||||
var fileName = "tsconfig.json";
|
||||
let fileName = "tsconfig.json";
|
||||
while (true) {
|
||||
if (sys.fileExists(fileName)) {
|
||||
return fileName;
|
||||
}
|
||||
var parentPath = getDirectoryPath(searchPath);
|
||||
let parentPath = getDirectoryPath(searchPath);
|
||||
if (parentPath === searchPath) {
|
||||
break;
|
||||
}
|
||||
@@ -35,7 +35,7 @@ namespace ts {
|
||||
// otherwise use toLowerCase as a canonical form.
|
||||
return sys.useCaseSensitiveFileNames ? fileName : fileName.toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
// returned by CScript sys environment
|
||||
let unsupportedFileEncodingErrorCode = -2147024809;
|
||||
|
||||
@@ -79,7 +79,7 @@ namespace ts {
|
||||
|
||||
function writeFile(fileName: string, data: string, writeByteOrderMark: boolean, onError?: (message: string) => void) {
|
||||
try {
|
||||
var start = new Date().getTime();
|
||||
let start = new Date().getTime();
|
||||
ensureDirectoriesExist(getDirectoryPath(normalizePath(fileName)));
|
||||
sys.writeFile(fileName, data, writeByteOrderMark);
|
||||
ioWriteTime += new Date().getTime() - start;
|
||||
@@ -239,8 +239,8 @@ namespace ts {
|
||||
|
||||
function emitWorker(program: Program, sourceFile: SourceFile, writeFileCallback: WriteFileCallback, cancellationToken: CancellationToken): EmitResult {
|
||||
// If the noEmitOnError flag is set, then check if we have any errors so far. If so,
|
||||
// immediately bail out. Note that we pass 'undefined' for 'sourceFile' so that we
|
||||
// get any preEmit diagnostics, not just the ones
|
||||
// immediately bail out. Note that we pass 'undefined' for 'sourceFile' so that we
|
||||
// get any preEmit diagnostics, not just the ones
|
||||
if (options.noEmitOnError && getPreEmitDiagnostics(program, /*sourceFile:*/ undefined, cancellationToken).length > 0) {
|
||||
return { diagnostics: [], sourceMaps: undefined, emitSkipped: true };
|
||||
}
|
||||
@@ -311,14 +311,14 @@ namespace ts {
|
||||
}
|
||||
catch (e) {
|
||||
if (e instanceof OperationCanceledException) {
|
||||
// We were canceled while performing the operation. Because our type checker
|
||||
// We were canceled while performing the operation. Because our type checker
|
||||
// might be a bad state, we need to throw it away.
|
||||
//
|
||||
// Note: we are overly agressive here. We do not actually *have* to throw away
|
||||
// the "noDiagnosticsTypeChecker". However, for simplicity, i'd like to keep
|
||||
// the lifetimes of these two TypeCheckers the same. Also, we generally only
|
||||
// cancel when the user has made a change anyways. And, in that case, we (the
|
||||
// program instance) will get thrown away anyways. So trying to keep one of
|
||||
// program instance) will get thrown away anyways. So trying to keep one of
|
||||
// these type checkers alive doesn't serve much purpose.
|
||||
noDiagnosticsTypeChecker = undefined;
|
||||
diagnosticsProducingTypeChecker = undefined;
|
||||
@@ -341,16 +341,16 @@ namespace ts {
|
||||
});
|
||||
}
|
||||
|
||||
function getDeclarationDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
|
||||
function getDeclarationDiagnosticsForFile(sourceFile: SourceFile, cancellationToken: CancellationToken): Diagnostic[] {
|
||||
return runWithCancellationToken(() => {
|
||||
if (!isDeclarationFile(sourceFile)) {
|
||||
let resolver = getDiagnosticsProducingTypeChecker().getEmitResolver(sourceFile, cancellationToken);
|
||||
// Don't actually write any files since we're just getting diagnostics.
|
||||
var writeFile: WriteFileCallback = () => { };
|
||||
let writeFile: WriteFileCallback = () => { };
|
||||
return ts.getDeclarationDiagnostics(getEmitHost(writeFile), resolver, sourceFile);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function getOptionsDiagnostics(): Diagnostic[] {
|
||||
let allDiagnostics: Diagnostic[] = [];
|
||||
@@ -396,7 +396,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
else {
|
||||
var nonTsFile: SourceFile = options.allowNonTsExtensions && findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd);
|
||||
let nonTsFile: SourceFile = options.allowNonTsExtensions && findSourceFile(fileName, isDefaultLib, refFile, refPos, refEnd);
|
||||
if (!nonTsFile) {
|
||||
if (options.allowNonTsExtensions) {
|
||||
diagnostic = Diagnostics.File_0_not_found;
|
||||
@@ -496,7 +496,7 @@ namespace ts {
|
||||
let moduleNameText = (<LiteralExpression>moduleNameExpr).text;
|
||||
if (moduleNameText) {
|
||||
let searchPath = basePath;
|
||||
let searchName: string;
|
||||
let searchName: string;
|
||||
while (true) {
|
||||
searchName = normalizePath(combinePaths(searchPath, moduleNameText));
|
||||
if (forEach(supportedExtensions, extension => findModuleSourceFile(searchName + extension, moduleNameExpr))) {
|
||||
@@ -513,7 +513,7 @@ namespace ts {
|
||||
}
|
||||
else if (node.kind === SyntaxKind.ModuleDeclaration && (<ModuleDeclaration>node).name.kind === SyntaxKind.StringLiteral && (node.flags & NodeFlags.Ambient || isDeclarationFile(file))) {
|
||||
// TypeScript 1.0 spec (April 2014): 12.1.6
|
||||
// An AmbientExternalModuleDeclaration declares an external module.
|
||||
// An AmbientExternalModuleDeclaration declares an external module.
|
||||
// This type of declaration is permitted only in the global module.
|
||||
// The StringLiteral must specify a top - level external module name.
|
||||
// Relative external module names are not permitted
|
||||
@@ -525,7 +525,7 @@ namespace ts {
|
||||
let moduleName = nameLiteral.text;
|
||||
if (moduleName) {
|
||||
// TypeScript 1.0 spec (April 2014): 12.1.6
|
||||
// An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules
|
||||
// An ExternalImportDeclaration in anAmbientExternalModuleDeclaration may reference other external modules
|
||||
// only through top - level external module names. Relative external module names are not permitted.
|
||||
let searchName = normalizePath(combinePaths(basePath, moduleName));
|
||||
forEach(supportedExtensions, extension => findModuleSourceFile(searchName + extension, nameLiteral));
|
||||
@@ -664,7 +664,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
else if (firstExternalModuleSourceFile && languageVersion < ScriptTarget.ES6 && !options.module) {
|
||||
// We cannot use createDiagnosticFromNode because nodes do not have parents yet
|
||||
// We cannot use createDiagnosticFromNode because nodes do not have parents yet
|
||||
let span = getErrorSpanForNode(firstExternalModuleSourceFile, firstExternalModuleSourceFile.externalModuleIndicator);
|
||||
diagnostics.add(createFileDiagnostic(firstExternalModuleSourceFile, span.start, span.length, Diagnostics.Cannot_compile_modules_unless_the_module_flag_is_provided));
|
||||
}
|
||||
@@ -691,7 +691,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (commonSourceDirectory && commonSourceDirectory[commonSourceDirectory.length - 1] !== directorySeparator) {
|
||||
// Make sure directory path ends with directory separator so this string can directly
|
||||
// Make sure directory path ends with directory separator so this string can directly
|
||||
// used to replace with "" to get the relative path of the source file and the relative path doesn't
|
||||
// start with / making it rooted path
|
||||
commonSourceDirectory += directorySeparator;
|
||||
@@ -707,12 +707,12 @@ namespace ts {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_noEmit_cannot_be_specified_with_option_declaration));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (options.emitDecoratorMetadata &&
|
||||
!options.experimentalDecorators) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_experimentalDecorators_must_also_be_specified_when_option_emitDecoratorMetadata_is_specified));
|
||||
}
|
||||
|
||||
|
||||
if (options.experimentalAsyncFunctions &&
|
||||
options.target !== ScriptTarget.ES6) {
|
||||
diagnostics.add(createCompilerDiagnostic(Diagnostics.Option_experimentalAsyncFunctions_cannot_be_specified_when_targeting_ES5_or_lower));
|
||||
|
||||
@@ -32,13 +32,13 @@ namespace ts {
|
||||
setScriptTarget(scriptTarget: ScriptTarget): void;
|
||||
setLanguageVariant(variant: LanguageVariant): void;
|
||||
setTextPos(textPos: number): void;
|
||||
// Invokes the provided callback then unconditionally restores the scanner to the state it
|
||||
// Invokes the provided callback then unconditionally restores the scanner to the state it
|
||||
// was in immediately prior to invoking the callback. The result of invoking the callback
|
||||
// is returned from this function.
|
||||
lookAhead<T>(callback: () => T): T;
|
||||
|
||||
// Invokes the provided callback. If the callback returns something falsy, then it restores
|
||||
// the scanner to the state it was in immediately prior to invoking the callback. If the
|
||||
// the scanner to the state it was in immediately prior to invoking the callback. If the
|
||||
// callback returns something truthy, then the scanner state is not rolled back. The result
|
||||
// of invoking the callback is returned from this function.
|
||||
tryScan<T>(callback: () => T): T;
|
||||
@@ -275,7 +275,7 @@ namespace ts {
|
||||
return textToToken[s];
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
/* @internal */
|
||||
export function computeLineStarts(text: string): number[] {
|
||||
let result: number[] = new Array();
|
||||
let pos = 0;
|
||||
@@ -307,22 +307,22 @@ namespace ts {
|
||||
return computePositionOfLineAndCharacter(getLineStarts(sourceFile), line, character);
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
/* @internal */
|
||||
export function computePositionOfLineAndCharacter(lineStarts: number[], line: number, character: number): number {
|
||||
Debug.assert(line >= 0 && line < lineStarts.length);
|
||||
return lineStarts[line] + character;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
/* @internal */
|
||||
export function getLineStarts(sourceFile: SourceFile): number[] {
|
||||
return sourceFile.lineMap || (sourceFile.lineMap = computeLineStarts(sourceFile.text));
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
/* @internal */
|
||||
export function computeLineAndCharacterOfPosition(lineStarts: number[], position: number) {
|
||||
let lineNumber = binarySearch(lineStarts, position);
|
||||
if (lineNumber < 0) {
|
||||
// If the actual position was not found,
|
||||
// If the actual position was not found,
|
||||
// the binary search returns the negative value of the next line start
|
||||
// e.g. if the line starts at [5, 10, 23, 80] and the position requested was 20
|
||||
// then the search will return -2
|
||||
@@ -355,125 +355,125 @@ namespace ts {
|
||||
ch === CharacterCodes.mathematicalSpace ||
|
||||
ch === CharacterCodes.ideographicSpace ||
|
||||
ch === CharacterCodes.byteOrderMark;
|
||||
}
|
||||
}
|
||||
|
||||
export function isLineBreak(ch: number): boolean {
|
||||
// ES5 7.3:
|
||||
// The ECMAScript line terminator characters are listed in Table 3.
|
||||
// Table 3: Line Terminator Characters
|
||||
// Code Unit Value Name Formal Name
|
||||
// \u000A Line Feed <LF>
|
||||
// \u000D Carriage Return <CR>
|
||||
// \u2028 Line separator <LS>
|
||||
// \u2029 Paragraph separator <PS>
|
||||
// Only the characters in Table 3 are treated as line terminators. Other new line or line
|
||||
// breaking characters are treated as white space but not as line terminators.
|
||||
export function isLineBreak(ch: number): boolean {
|
||||
// ES5 7.3:
|
||||
// The ECMAScript line terminator characters are listed in Table 3.
|
||||
// Table 3: Line Terminator Characters
|
||||
// Code Unit Value Name Formal Name
|
||||
// \u000A Line Feed <LF>
|
||||
// \u000D Carriage Return <CR>
|
||||
// \u2028 Line separator <LS>
|
||||
// \u2029 Paragraph separator <PS>
|
||||
// Only the characters in Table 3 are treated as line terminators. Other new line or line
|
||||
// breaking characters are treated as white space but not as line terminators.
|
||||
|
||||
return ch === CharacterCodes.lineFeed ||
|
||||
ch === CharacterCodes.carriageReturn ||
|
||||
ch === CharacterCodes.lineSeparator ||
|
||||
ch === CharacterCodes.paragraphSeparator;
|
||||
}
|
||||
return ch === CharacterCodes.lineFeed ||
|
||||
ch === CharacterCodes.carriageReturn ||
|
||||
ch === CharacterCodes.lineSeparator ||
|
||||
ch === CharacterCodes.paragraphSeparator;
|
||||
}
|
||||
|
||||
function isDigit(ch: number): boolean {
|
||||
return ch >= CharacterCodes._0 && ch <= CharacterCodes._9;
|
||||
}
|
||||
function isDigit(ch: number): boolean {
|
||||
return ch >= CharacterCodes._0 && ch <= CharacterCodes._9;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function isOctalDigit(ch: number): boolean {
|
||||
return ch >= CharacterCodes._0 && ch <= CharacterCodes._7;
|
||||
}
|
||||
/* @internal */
|
||||
export function isOctalDigit(ch: number): boolean {
|
||||
return ch >= CharacterCodes._0 && ch <= CharacterCodes._7;
|
||||
}
|
||||
|
||||
export function couldStartTrivia(text: string, pos: number): boolean {
|
||||
// Keep in sync with skipTrivia
|
||||
let ch = text.charCodeAt(pos);
|
||||
switch (ch) {
|
||||
case CharacterCodes.carriageReturn:
|
||||
case CharacterCodes.lineFeed:
|
||||
case CharacterCodes.tab:
|
||||
case CharacterCodes.verticalTab:
|
||||
case CharacterCodes.formFeed:
|
||||
case CharacterCodes.space:
|
||||
case CharacterCodes.slash:
|
||||
// starts of normal trivia
|
||||
case CharacterCodes.lessThan:
|
||||
case CharacterCodes.equals:
|
||||
case CharacterCodes.greaterThan:
|
||||
// Starts of conflict marker trivia
|
||||
return true;
|
||||
default:
|
||||
return ch > CharacterCodes.maxAsciiCharacter;
|
||||
}
|
||||
}
|
||||
export function couldStartTrivia(text: string, pos: number): boolean {
|
||||
// Keep in sync with skipTrivia
|
||||
let ch = text.charCodeAt(pos);
|
||||
switch (ch) {
|
||||
case CharacterCodes.carriageReturn:
|
||||
case CharacterCodes.lineFeed:
|
||||
case CharacterCodes.tab:
|
||||
case CharacterCodes.verticalTab:
|
||||
case CharacterCodes.formFeed:
|
||||
case CharacterCodes.space:
|
||||
case CharacterCodes.slash:
|
||||
// starts of normal trivia
|
||||
case CharacterCodes.lessThan:
|
||||
case CharacterCodes.equals:
|
||||
case CharacterCodes.greaterThan:
|
||||
// Starts of conflict marker trivia
|
||||
return true;
|
||||
default:
|
||||
return ch > CharacterCodes.maxAsciiCharacter;
|
||||
}
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function skipTrivia(text: string, pos: number, stopAfterLineBreak?: boolean): number {
|
||||
// Keep in sync with couldStartTrivia
|
||||
while (true) {
|
||||
let ch = text.charCodeAt(pos);
|
||||
switch (ch) {
|
||||
case CharacterCodes.carriageReturn:
|
||||
if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) {
|
||||
pos++;
|
||||
}
|
||||
case CharacterCodes.lineFeed:
|
||||
pos++;
|
||||
if (stopAfterLineBreak) {
|
||||
return pos;
|
||||
}
|
||||
continue;
|
||||
case CharacterCodes.tab:
|
||||
case CharacterCodes.verticalTab:
|
||||
case CharacterCodes.formFeed:
|
||||
case CharacterCodes.space:
|
||||
pos++;
|
||||
continue;
|
||||
case CharacterCodes.slash:
|
||||
if (text.charCodeAt(pos + 1) === CharacterCodes.slash) {
|
||||
pos += 2;
|
||||
while (pos < text.length) {
|
||||
if (isLineBreak(text.charCodeAt(pos))) {
|
||||
break;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (text.charCodeAt(pos + 1) === CharacterCodes.asterisk) {
|
||||
pos += 2;
|
||||
while (pos < text.length) {
|
||||
if (text.charCodeAt(pos) === CharacterCodes.asterisk && text.charCodeAt(pos + 1) === CharacterCodes.slash) {
|
||||
pos += 2;
|
||||
break;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
/* @internal */
|
||||
export function skipTrivia(text: string, pos: number, stopAfterLineBreak?: boolean): number {
|
||||
// Keep in sync with couldStartTrivia
|
||||
while (true) {
|
||||
let ch = text.charCodeAt(pos);
|
||||
switch (ch) {
|
||||
case CharacterCodes.carriageReturn:
|
||||
if (text.charCodeAt(pos + 1) === CharacterCodes.lineFeed) {
|
||||
pos++;
|
||||
}
|
||||
case CharacterCodes.lineFeed:
|
||||
pos++;
|
||||
if (stopAfterLineBreak) {
|
||||
return pos;
|
||||
}
|
||||
continue;
|
||||
case CharacterCodes.tab:
|
||||
case CharacterCodes.verticalTab:
|
||||
case CharacterCodes.formFeed:
|
||||
case CharacterCodes.space:
|
||||
pos++;
|
||||
continue;
|
||||
case CharacterCodes.slash:
|
||||
if (text.charCodeAt(pos + 1) === CharacterCodes.slash) {
|
||||
pos += 2;
|
||||
while (pos < text.length) {
|
||||
if (isLineBreak(text.charCodeAt(pos))) {
|
||||
break;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (text.charCodeAt(pos + 1) === CharacterCodes.asterisk) {
|
||||
pos += 2;
|
||||
while (pos < text.length) {
|
||||
if (text.charCodeAt(pos) === CharacterCodes.asterisk && text.charCodeAt(pos + 1) === CharacterCodes.slash) {
|
||||
pos += 2;
|
||||
break;
|
||||
}
|
||||
pos++;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
case CharacterCodes.lessThan:
|
||||
case CharacterCodes.equals:
|
||||
case CharacterCodes.greaterThan:
|
||||
if (isConflictMarkerTrivia(text, pos)) {
|
||||
pos = scanConflictMarkerTrivia(text, pos);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
case CharacterCodes.lessThan:
|
||||
case CharacterCodes.equals:
|
||||
case CharacterCodes.greaterThan:
|
||||
if (isConflictMarkerTrivia(text, pos)) {
|
||||
pos = scanConflictMarkerTrivia(text, pos);
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch) || isLineBreak(ch))) {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
default:
|
||||
if (ch > CharacterCodes.maxAsciiCharacter && (isWhiteSpace(ch) || isLineBreak(ch))) {
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return pos;
|
||||
}
|
||||
}
|
||||
|
||||
// All conflict markers consist of the same character repeated seven times. If it is
|
||||
// a <<<<<<< or >>>>>>> marker then it is also followd by a space.
|
||||
// All conflict markers consist of the same character repeated seven times. If it is
|
||||
// a <<<<<<< or >>>>>>> marker then it is also followd by a space.
|
||||
let mergeConflictMarkerLength = "<<<<<<<".length;
|
||||
|
||||
function isConflictMarkerTrivia(text: string, pos: number) {
|
||||
@@ -528,12 +528,12 @@ namespace ts {
|
||||
return pos;
|
||||
}
|
||||
|
||||
// Extract comments from the given source text starting at the given position. If trailing is
|
||||
// false, whitespace is skipped until the first line break and comments between that location
|
||||
// and the next token are returned.If trailing is true, comments occurring between the given
|
||||
// position and the next line break are returned.The return value is an array containing a
|
||||
// TextRange for each comment. Single-line comment ranges include the beginning '//' characters
|
||||
// but not the ending line break. Multi - line comment ranges include the beginning '/* and
|
||||
// Extract comments from the given source text starting at the given position. If trailing is
|
||||
// false, whitespace is skipped until the first line break and comments between that location
|
||||
// and the next token are returned.If trailing is true, comments occurring between the given
|
||||
// position and the next line break are returned.The return value is an array containing a
|
||||
// TextRange for each comment. Single-line comment ranges include the beginning '//' characters
|
||||
// but not the ending line break. Multi - line comment ranges include the beginning '/* and
|
||||
// ending '*/' characters.The return value is undefined if no comments were found.
|
||||
function getCommentRanges(text: string, pos: number, trailing: boolean): CommentRange[] {
|
||||
let result: CommentRange[];
|
||||
@@ -629,9 +629,9 @@ namespace ts {
|
||||
ch >= CharacterCodes._0 && ch <= CharacterCodes._9 || ch === CharacterCodes.$ || ch === CharacterCodes._ ||
|
||||
ch > CharacterCodes.maxAsciiCharacter && isUnicodeIdentifierPart(ch, languageVersion);
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
// Creates a scanner over a (possibly unspecified) range of a piece of text.
|
||||
|
||||
/* @internal */
|
||||
// Creates a scanner over a (possibly unspecified) range of a piece of text.
|
||||
export function createScanner(languageVersion: ScriptTarget,
|
||||
skipTrivia: boolean,
|
||||
languageVariant = LanguageVariant.Standard,
|
||||
@@ -640,16 +640,16 @@ namespace ts {
|
||||
start?: number,
|
||||
length?: number): Scanner {
|
||||
// Current position (end position of text of current token)
|
||||
let pos: number;
|
||||
let pos: number;
|
||||
|
||||
// end of text
|
||||
let end: number;
|
||||
let end: number;
|
||||
|
||||
// Start position of whitespace before current token
|
||||
let startPos: number;
|
||||
let startPos: number;
|
||||
|
||||
// Start position of text of current token
|
||||
let tokenPos: number;
|
||||
let tokenPos: number;
|
||||
|
||||
let token: SyntaxKind;
|
||||
let tokenValue: string;
|
||||
@@ -735,7 +735,7 @@ namespace ts {
|
||||
}
|
||||
return +(text.substring(start, pos));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scans the given number of hexadecimal digits in the text,
|
||||
* returning -1 if the given number is unavailable.
|
||||
@@ -743,7 +743,7 @@ namespace ts {
|
||||
function scanExactNumberOfHexDigits(count: number): number {
|
||||
return scanHexDigits(/*minCount*/ count, /*scanAsManyAsPossible*/ false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Scans as many hexadecimal digits as are available in the text,
|
||||
* returning -1 if the given number of digits was unavailable.
|
||||
@@ -821,7 +821,7 @@ namespace ts {
|
||||
|
||||
pos++;
|
||||
let start = pos;
|
||||
let contents = ""
|
||||
let contents = "";
|
||||
let resultingToken: SyntaxKind;
|
||||
|
||||
while (true) {
|
||||
@@ -916,13 +916,13 @@ namespace ts {
|
||||
pos++;
|
||||
return scanExtendedUnicodeEscape();
|
||||
}
|
||||
|
||||
|
||||
// '\uDDDD'
|
||||
return scanHexadecimalEscape(/*numDigits*/ 4)
|
||||
|
||||
return scanHexadecimalEscape(/*numDigits*/ 4);
|
||||
|
||||
case CharacterCodes.x:
|
||||
// '\xDD'
|
||||
return scanHexadecimalEscape(/*numDigits*/ 2)
|
||||
return scanHexadecimalEscape(/*numDigits*/ 2);
|
||||
|
||||
// when encountering a LineContinuation (i.e. a backslash and a line terminator sequence),
|
||||
// the line terminator is interpreted to be "the empty code unit sequence".
|
||||
@@ -934,31 +934,31 @@ namespace ts {
|
||||
case CharacterCodes.lineFeed:
|
||||
case CharacterCodes.lineSeparator:
|
||||
case CharacterCodes.paragraphSeparator:
|
||||
return ""
|
||||
return "";
|
||||
default:
|
||||
return String.fromCharCode(ch);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function scanHexadecimalEscape(numDigits: number): string {
|
||||
let escapedValue = scanExactNumberOfHexDigits(numDigits);
|
||||
|
||||
|
||||
if (escapedValue >= 0) {
|
||||
return String.fromCharCode(escapedValue);
|
||||
}
|
||||
else {
|
||||
error(Diagnostics.Hexadecimal_digit_expected);
|
||||
return ""
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function scanExtendedUnicodeEscape(): string {
|
||||
let escapedValue = scanMinimumNumberOfHexDigits(1);
|
||||
let isInvalidExtendedEscape = false;
|
||||
|
||||
// Validate the value of the digit
|
||||
if (escapedValue < 0) {
|
||||
error(Diagnostics.Hexadecimal_digit_expected)
|
||||
error(Diagnostics.Hexadecimal_digit_expected);
|
||||
isInvalidExtendedEscape = true;
|
||||
}
|
||||
else if (escapedValue > 0x10FFFF) {
|
||||
@@ -985,18 +985,18 @@ namespace ts {
|
||||
|
||||
return utf16EncodeAsString(escapedValue);
|
||||
}
|
||||
|
||||
|
||||
// Derived from the 10.1.1 UTF16Encoding of the ES6 Spec.
|
||||
function utf16EncodeAsString(codePoint: number): string {
|
||||
Debug.assert(0x0 <= codePoint && codePoint <= 0x10FFFF);
|
||||
|
||||
|
||||
if (codePoint <= 65535) {
|
||||
return String.fromCharCode(codePoint);
|
||||
}
|
||||
|
||||
|
||||
let codeUnit1 = Math.floor((codePoint - 65536) / 1024) + 0xD800;
|
||||
let codeUnit2 = ((codePoint - 65536) % 1024) + 0xDC00;
|
||||
|
||||
|
||||
return String.fromCharCode(codeUnit1, codeUnit2);
|
||||
}
|
||||
|
||||
@@ -1058,7 +1058,7 @@ namespace ts {
|
||||
let value = 0;
|
||||
// For counting number of digits; Valid binaryIntegerLiteral must have at least one binary digit following B or b.
|
||||
// Similarly valid octalIntegerLiteral must have at least one octal digit following o or O.
|
||||
let numberOfDigits = 0;
|
||||
let numberOfDigits = 0;
|
||||
while (true) {
|
||||
let ch = text.charCodeAt(pos);
|
||||
let valueOfCh = ch - CharacterCodes._0;
|
||||
@@ -1132,7 +1132,7 @@ namespace ts {
|
||||
tokenValue = scanString();
|
||||
return token = SyntaxKind.StringLiteral;
|
||||
case CharacterCodes.backtick:
|
||||
return token = scanTemplateAndSetTokenValue()
|
||||
return token = scanTemplateAndSetTokenValue();
|
||||
case CharacterCodes.percent:
|
||||
if (text.charCodeAt(pos + 1) === CharacterCodes.equals) {
|
||||
return pos += 2, token = SyntaxKind.PercentEqualsToken;
|
||||
@@ -1444,14 +1444,14 @@ namespace ts {
|
||||
// regex. Report error and return what we have so far.
|
||||
if (p >= end) {
|
||||
tokenIsUnterminated = true;
|
||||
error(Diagnostics.Unterminated_regular_expression_literal)
|
||||
error(Diagnostics.Unterminated_regular_expression_literal);
|
||||
break;
|
||||
}
|
||||
|
||||
let ch = text.charCodeAt(p);
|
||||
if (isLineBreak(ch)) {
|
||||
tokenIsUnterminated = true;
|
||||
error(Diagnostics.Unterminated_regular_expression_literal)
|
||||
error(Diagnostics.Unterminated_regular_expression_literal);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -1543,7 +1543,7 @@ namespace ts {
|
||||
let ch = text.charCodeAt(pos);
|
||||
if (ch === CharacterCodes.minus || ((firstCharPosition === pos) ? isIdentifierStart(ch) : isIdentifierPart(ch))) {
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
break;
|
||||
}
|
||||
@@ -1552,7 +1552,7 @@ namespace ts {
|
||||
}
|
||||
return token;
|
||||
}
|
||||
|
||||
|
||||
function speculationHelper<T>(callback: () => T, isLookahead: boolean): T {
|
||||
let savePos = pos;
|
||||
let saveStartPos = startPos;
|
||||
|
||||
@@ -29,6 +29,9 @@ namespace ts {
|
||||
declare var process: any;
|
||||
declare var global: any;
|
||||
declare var __filename: string;
|
||||
declare var Buffer: {
|
||||
new (str: string, encoding ?: string): any;
|
||||
}
|
||||
|
||||
declare class Enumerator {
|
||||
public atEnd(): boolean;
|
||||
@@ -41,16 +44,16 @@ namespace ts {
|
||||
|
||||
function getWScriptSystem(): System {
|
||||
|
||||
var fso = new ActiveXObject("Scripting.FileSystemObject");
|
||||
let fso = new ActiveXObject("Scripting.FileSystemObject");
|
||||
|
||||
var fileStream = new ActiveXObject("ADODB.Stream");
|
||||
let fileStream = new ActiveXObject("ADODB.Stream");
|
||||
fileStream.Type = 2 /*text*/;
|
||||
|
||||
var binaryStream = new ActiveXObject("ADODB.Stream");
|
||||
let binaryStream = new ActiveXObject("ADODB.Stream");
|
||||
binaryStream.Type = 1 /*binary*/;
|
||||
|
||||
var args: string[] = [];
|
||||
for (var i = 0; i < WScript.Arguments.length; i++) {
|
||||
let args: string[] = [];
|
||||
for (let i = 0; i < WScript.Arguments.length; i++) {
|
||||
args[i] = WScript.Arguments.Item(i);
|
||||
}
|
||||
|
||||
@@ -68,7 +71,7 @@ namespace ts {
|
||||
// Load file and read the first two bytes into a string with no interpretation
|
||||
fileStream.Charset = "x-ansi";
|
||||
fileStream.LoadFromFile(fileName);
|
||||
var bom = fileStream.ReadText(2) || "";
|
||||
let bom = fileStream.ReadText(2) || "";
|
||||
// Position must be at 0 before encoding can be changed
|
||||
fileStream.Position = 0;
|
||||
// [0xFF,0xFE] and [0xFE,0xFF] mean utf-16 (little or big endian), otherwise default to utf-8
|
||||
@@ -114,28 +117,28 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getNames(collection: any): string[]{
|
||||
var result: string[] = [];
|
||||
for (var e = new Enumerator(collection); !e.atEnd(); e.moveNext()) {
|
||||
let result: string[] = [];
|
||||
for (let e = new Enumerator(collection); !e.atEnd(); e.moveNext()) {
|
||||
result.push(e.item().Name);
|
||||
}
|
||||
return result.sort();
|
||||
}
|
||||
|
||||
function readDirectory(path: string, extension?: string, exclude?: string[]): string[] {
|
||||
var result: string[] = [];
|
||||
let result: string[] = [];
|
||||
exclude = map(exclude, s => getCanonicalPath(combinePaths(path, s)));
|
||||
visitDirectory(path);
|
||||
return result;
|
||||
function visitDirectory(path: string) {
|
||||
var folder = fso.GetFolder(path || ".");
|
||||
var files = getNames(folder.files);
|
||||
let folder = fso.GetFolder(path || ".");
|
||||
let files = getNames(folder.files);
|
||||
for (let current of files) {
|
||||
let name = combinePaths(path, current);
|
||||
if ((!extension || fileExtensionIs(name, extension)) && !contains(exclude, getCanonicalPath(name))) {
|
||||
result.push(name);
|
||||
}
|
||||
}
|
||||
var subfolders = getNames(folder.subfolders);
|
||||
let subfolders = getNames(folder.subfolders);
|
||||
for (let current of subfolders) {
|
||||
let name = combinePaths(path, current);
|
||||
if (!contains(exclude, getCanonicalPath(name))) {
|
||||
@@ -197,14 +200,14 @@ namespace ts {
|
||||
if (!_fs.existsSync(fileName)) {
|
||||
return undefined;
|
||||
}
|
||||
var buffer = _fs.readFileSync(fileName);
|
||||
var len = buffer.length;
|
||||
let buffer = _fs.readFileSync(fileName);
|
||||
let len = buffer.length;
|
||||
if (len >= 2 && buffer[0] === 0xFE && buffer[1] === 0xFF) {
|
||||
// Big endian UTF-16 byte order mark detected. Since big endian is not supported by node.js,
|
||||
// flip all byte pairs and treat as little endian.
|
||||
len &= ~1;
|
||||
for (var i = 0; i < len; i += 2) {
|
||||
var temp = buffer[i];
|
||||
for (let i = 0; i < len; i += 2) {
|
||||
let temp = buffer[i];
|
||||
buffer[i] = buffer[i + 1];
|
||||
buffer[i + 1] = temp;
|
||||
}
|
||||
@@ -236,17 +239,17 @@ namespace ts {
|
||||
}
|
||||
|
||||
function readDirectory(path: string, extension?: string, exclude?: string[]): string[] {
|
||||
var result: string[] = [];
|
||||
let result: string[] = [];
|
||||
exclude = map(exclude, s => getCanonicalPath(combinePaths(path, s)));
|
||||
visitDirectory(path);
|
||||
return result;
|
||||
function visitDirectory(path: string) {
|
||||
var files = _fs.readdirSync(path || ".").sort();
|
||||
var directories: string[] = [];
|
||||
let files = _fs.readdirSync(path || ".").sort();
|
||||
let directories: string[] = [];
|
||||
for (let current of files) {
|
||||
var name = combinePaths(path, current);
|
||||
let name = combinePaths(path, current);
|
||||
if (!contains(exclude, getCanonicalPath(name))) {
|
||||
var stat = _fs.statSync(name);
|
||||
let stat = _fs.statSync(name);
|
||||
if (stat.isFile()) {
|
||||
if (!extension || fileExtensionIs(name, extension)) {
|
||||
result.push(name);
|
||||
@@ -267,10 +270,17 @@ namespace ts {
|
||||
args: process.argv.slice(2),
|
||||
newLine: _os.EOL,
|
||||
useCaseSensitiveFileNames: useCaseSensitiveFileNames,
|
||||
write(s: string): void {
|
||||
write(s: string): void {
|
||||
var buffer = new Buffer(s, 'utf8');
|
||||
var offset: number = 0;
|
||||
var toWrite: number = buffer.length;
|
||||
var written = 0;
|
||||
// 1 is a standard descriptor for stdout
|
||||
_fs.writeSync(1, s);
|
||||
},
|
||||
while ((written = _fs.writeSync(1, buffer, offset, toWrite)) < toWrite) {
|
||||
offset += written;
|
||||
toWrite -= written;
|
||||
}
|
||||
},
|
||||
readFile,
|
||||
writeFile,
|
||||
watchFile: (fileName, callback) => {
|
||||
@@ -331,4 +341,4 @@ namespace ts {
|
||||
return undefined; // Unsupported host
|
||||
}
|
||||
})();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,15 +11,15 @@ namespace ts {
|
||||
* and if it is, attempts to set the appropriate language.
|
||||
*/
|
||||
function validateLocaleAndSetLanguage(locale: string, errors: Diagnostic[]): boolean {
|
||||
var matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase());
|
||||
let matchResult = /^([a-z]+)([_\-]([a-z]+))?$/.exec(locale.toLowerCase());
|
||||
|
||||
if (!matchResult) {
|
||||
errors.push(createCompilerDiagnostic(Diagnostics.Locale_must_be_of_the_form_language_or_language_territory_For_example_0_or_1, 'en', 'ja-jp'));
|
||||
return false;
|
||||
}
|
||||
|
||||
var language = matchResult[1];
|
||||
var territory = matchResult[3];
|
||||
let language = matchResult[1];
|
||||
let territory = matchResult[3];
|
||||
|
||||
// First try the entire locale, then fall back to just language if that's all we have.
|
||||
if (!trySetLanguageAndTerritory(language, territory, errors) &&
|
||||
@@ -33,10 +33,10 @@ namespace ts {
|
||||
}
|
||||
|
||||
function trySetLanguageAndTerritory(language: string, territory: string, errors: Diagnostic[]): boolean {
|
||||
var compilerFilePath = normalizePath(sys.getExecutingFilePath());
|
||||
var containingDirectoryPath = getDirectoryPath(compilerFilePath);
|
||||
let compilerFilePath = normalizePath(sys.getExecutingFilePath());
|
||||
let containingDirectoryPath = getDirectoryPath(compilerFilePath);
|
||||
|
||||
var filePath = combinePaths(containingDirectoryPath, language);
|
||||
let filePath = combinePaths(containingDirectoryPath, language);
|
||||
|
||||
if (territory) {
|
||||
filePath = filePath + "-" + territory;
|
||||
@@ -49,8 +49,9 @@ namespace ts {
|
||||
}
|
||||
|
||||
// TODO: Add codePage support for readFile?
|
||||
let fileContents = '';
|
||||
try {
|
||||
var fileContents = sys.readFile(filePath);
|
||||
fileContents = sys.readFile(filePath);
|
||||
}
|
||||
catch (e) {
|
||||
errors.push(createCompilerDiagnostic(Diagnostics.Unable_to_open_file_0, filePath));
|
||||
@@ -68,7 +69,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function countLines(program: Program): number {
|
||||
var count = 0;
|
||||
let count = 0;
|
||||
forEach(program.getSourceFiles(), file => {
|
||||
count += getLineStarts(file).length;
|
||||
});
|
||||
@@ -76,27 +77,27 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getDiagnosticText(message: DiagnosticMessage, ...args: any[]): string {
|
||||
var diagnostic = createCompilerDiagnostic.apply(undefined, arguments);
|
||||
let diagnostic = createCompilerDiagnostic.apply(undefined, arguments);
|
||||
return <string>diagnostic.messageText;
|
||||
}
|
||||
|
||||
function reportDiagnostic(diagnostic: Diagnostic) {
|
||||
var output = "";
|
||||
|
||||
let output = "";
|
||||
|
||||
if (diagnostic.file) {
|
||||
var loc = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
||||
let loc = getLineAndCharacterOfPosition(diagnostic.file, diagnostic.start);
|
||||
|
||||
output += `${ diagnostic.file.fileName }(${ loc.line + 1 },${ loc.character + 1 }): `;
|
||||
}
|
||||
|
||||
var category = DiagnosticCategory[diagnostic.category].toLowerCase();
|
||||
let category = DiagnosticCategory[diagnostic.category].toLowerCase();
|
||||
output += `${ category } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, sys.newLine) }${ sys.newLine }`;
|
||||
|
||||
sys.write(output);
|
||||
}
|
||||
|
||||
function reportDiagnostics(diagnostics: Diagnostic[]) {
|
||||
for (var i = 0; i < diagnostics.length; i++) {
|
||||
for (let i = 0; i < diagnostics.length; i++) {
|
||||
reportDiagnostic(diagnostics[i]);
|
||||
}
|
||||
}
|
||||
@@ -133,15 +134,15 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function executeCommandLine(args: string[]): void {
|
||||
var commandLine = parseCommandLine(args);
|
||||
var configFileName: string; // Configuration file name (if any)
|
||||
var configFileWatcher: FileWatcher; // Configuration file watcher
|
||||
var cachedProgram: Program; // Program cached from last compilation
|
||||
var rootFileNames: string[]; // Root fileNames for compilation
|
||||
var compilerOptions: CompilerOptions; // Compiler options for compilation
|
||||
var compilerHost: CompilerHost; // Compiler host
|
||||
var hostGetSourceFile: typeof compilerHost.getSourceFile; // getSourceFile method from default host
|
||||
var timerHandle: number; // Handle for 0.25s wait timer
|
||||
let commandLine = parseCommandLine(args);
|
||||
let configFileName: string; // Configuration file name (if any)
|
||||
let configFileWatcher: FileWatcher; // Configuration file watcher
|
||||
let cachedProgram: Program; // Program cached from last compilation
|
||||
let rootFileNames: string[]; // Root fileNames for compilation
|
||||
let compilerOptions: CompilerOptions; // Compiler options for compilation
|
||||
let compilerHost: CompilerHost; // Compiler host
|
||||
let hostGetSourceFile: typeof compilerHost.getSourceFile; // getSourceFile method from default host
|
||||
let timerHandle: number; // Handle for 0.25s wait timer
|
||||
|
||||
if (commandLine.options.locale) {
|
||||
if (!isJSONSupported()) {
|
||||
@@ -181,7 +182,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
else if (commandLine.fileNames.length === 0 && isJSONSupported()) {
|
||||
var searchPath = normalizePath(sys.getCurrentDirectory());
|
||||
let searchPath = normalizePath(sys.getCurrentDirectory());
|
||||
configFileName = findConfigFile(searchPath);
|
||||
}
|
||||
|
||||
@@ -247,14 +248,14 @@ namespace ts {
|
||||
function getSourceFile(fileName: string, languageVersion: ScriptTarget, onError ?: (message: string) => void) {
|
||||
// Return existing SourceFile object if one is available
|
||||
if (cachedProgram) {
|
||||
var sourceFile = cachedProgram.getSourceFile(fileName);
|
||||
let sourceFile = cachedProgram.getSourceFile(fileName);
|
||||
// A modified source file has no watcher and should not be reused
|
||||
if (sourceFile && sourceFile.fileWatcher) {
|
||||
return sourceFile;
|
||||
}
|
||||
}
|
||||
// Use default host function
|
||||
var sourceFile = hostGetSourceFile(fileName, languageVersion, onError);
|
||||
let sourceFile = hostGetSourceFile(fileName, languageVersion, onError);
|
||||
if (sourceFile && compilerOptions.watch) {
|
||||
// Attach a file watcher
|
||||
sourceFile.fileWatcher = sys.watchFile(sourceFile.fileName, () => sourceFileChanged(sourceFile));
|
||||
@@ -265,7 +266,7 @@ namespace ts {
|
||||
// Change cached program to the given program
|
||||
function setCachedProgram(program: Program) {
|
||||
if (cachedProgram) {
|
||||
var newSourceFiles = program ? program.getSourceFiles() : undefined;
|
||||
let newSourceFiles = program ? program.getSourceFiles() : undefined;
|
||||
forEach(cachedProgram.getSourceFiles(), sourceFile => {
|
||||
if (!(newSourceFiles && contains(newSourceFiles, sourceFile))) {
|
||||
if (sourceFile.fileWatcher) {
|
||||
@@ -316,8 +317,8 @@ namespace ts {
|
||||
checkTime = 0;
|
||||
emitTime = 0;
|
||||
|
||||
var program = createProgram(fileNames, compilerOptions, compilerHost);
|
||||
var exitStatus = compileProgram();
|
||||
let program = createProgram(fileNames, compilerOptions, compilerHost);
|
||||
let exitStatus = compileProgram();
|
||||
|
||||
if (compilerOptions.listFiles) {
|
||||
forEach(program.getSourceFiles(), file => {
|
||||
@@ -326,7 +327,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (compilerOptions.diagnostics) {
|
||||
var memoryUsed = sys.getMemoryUsage ? sys.getMemoryUsage() : -1;
|
||||
let memoryUsed = sys.getMemoryUsage ? sys.getMemoryUsage() : -1;
|
||||
reportCountStatistic("Files", program.getSourceFiles().length);
|
||||
reportCountStatistic("Lines", countLines(program));
|
||||
reportCountStatistic("Nodes", program.getNodeCount());
|
||||
@@ -354,18 +355,18 @@ namespace ts {
|
||||
return { program, exitStatus };
|
||||
|
||||
function compileProgram(): ExitStatus {
|
||||
// First get any syntactic errors.
|
||||
var diagnostics = program.getSyntacticDiagnostics();
|
||||
// First get any syntactic errors.
|
||||
let diagnostics = program.getSyntacticDiagnostics();
|
||||
reportDiagnostics(diagnostics);
|
||||
|
||||
// If we didn't have any syntactic errors, then also try getting the global and
|
||||
// If we didn't have any syntactic errors, then also try getting the global and
|
||||
// semantic errors.
|
||||
if (diagnostics.length === 0) {
|
||||
var diagnostics = program.getGlobalDiagnostics();
|
||||
let diagnostics = program.getGlobalDiagnostics();
|
||||
reportDiagnostics(diagnostics);
|
||||
|
||||
if (diagnostics.length === 0) {
|
||||
var diagnostics = program.getSemanticDiagnostics();
|
||||
let diagnostics = program.getSemanticDiagnostics();
|
||||
reportDiagnostics(diagnostics);
|
||||
}
|
||||
}
|
||||
@@ -378,7 +379,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Otherwise, emit and report any errors we ran into.
|
||||
var emitOutput = program.emit();
|
||||
let emitOutput = program.emit();
|
||||
reportDiagnostics(emitOutput.diagnostics);
|
||||
|
||||
// If the emitter didn't emit anything, then pass that value along.
|
||||
@@ -401,22 +402,22 @@ namespace ts {
|
||||
}
|
||||
|
||||
function printHelp() {
|
||||
var output = "";
|
||||
let output = "";
|
||||
|
||||
// We want to align our "syntax" and "examples" commands to a certain margin.
|
||||
var syntaxLength = getDiagnosticText(Diagnostics.Syntax_Colon_0, "").length;
|
||||
var examplesLength = getDiagnosticText(Diagnostics.Examples_Colon_0, "").length;
|
||||
var marginLength = Math.max(syntaxLength, examplesLength);
|
||||
let syntaxLength = getDiagnosticText(Diagnostics.Syntax_Colon_0, "").length;
|
||||
let examplesLength = getDiagnosticText(Diagnostics.Examples_Colon_0, "").length;
|
||||
let marginLength = Math.max(syntaxLength, examplesLength);
|
||||
|
||||
// Build up the syntactic skeleton.
|
||||
var syntax = makePadding(marginLength - syntaxLength);
|
||||
let syntax = makePadding(marginLength - syntaxLength);
|
||||
syntax += "tsc [" + getDiagnosticText(Diagnostics.options) + "] [" + getDiagnosticText(Diagnostics.file) + " ...]";
|
||||
|
||||
output += getDiagnosticText(Diagnostics.Syntax_Colon_0, syntax);
|
||||
output += sys.newLine + sys.newLine;
|
||||
|
||||
// Build up the list of examples.
|
||||
var padding = makePadding(marginLength);
|
||||
let padding = makePadding(marginLength);
|
||||
output += getDiagnosticText(Diagnostics.Examples_Colon_0, makePadding(marginLength - examplesLength) + "tsc hello.ts") + sys.newLine;
|
||||
output += padding + "tsc --out file.js file.ts" + sys.newLine;
|
||||
output += padding + "tsc @args.txt" + sys.newLine;
|
||||
@@ -425,17 +426,17 @@ namespace ts {
|
||||
output += getDiagnosticText(Diagnostics.Options_Colon) + sys.newLine;
|
||||
|
||||
// Sort our options by their names, (e.g. "--noImplicitAny" comes before "--watch")
|
||||
var optsList = filter(optionDeclarations.slice(), v => !v.experimental);
|
||||
let optsList = filter(optionDeclarations.slice(), v => !v.experimental);
|
||||
optsList.sort((a, b) => compareValues<string>(a.name.toLowerCase(), b.name.toLowerCase()));
|
||||
|
||||
// We want our descriptions to align at the same column in our output,
|
||||
// so we keep track of the longest option usage string.
|
||||
var marginLength = 0;
|
||||
var usageColumn: string[] = []; // Things like "-d, --declaration" go in here.
|
||||
var descriptionColumn: string[] = [];
|
||||
marginLength = 0;
|
||||
let usageColumn: string[] = []; // Things like "-d, --declaration" go in here.
|
||||
let descriptionColumn: string[] = [];
|
||||
|
||||
for (var i = 0; i < optsList.length; i++) {
|
||||
var option = optsList[i];
|
||||
for (let i = 0; i < optsList.length; i++) {
|
||||
let option = optsList[i];
|
||||
|
||||
// If an option lacks a description,
|
||||
// it is not officially supported.
|
||||
@@ -443,7 +444,7 @@ namespace ts {
|
||||
continue;
|
||||
}
|
||||
|
||||
var usageText = " ";
|
||||
let usageText = " ";
|
||||
if (option.shortName) {
|
||||
usageText += "-" + option.shortName;
|
||||
usageText += getParamType(option);
|
||||
@@ -461,15 +462,15 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Special case that can't fit in the loop.
|
||||
var usageText = " @<" + getDiagnosticText(Diagnostics.file) + ">";
|
||||
let usageText = " @<" + getDiagnosticText(Diagnostics.file) + ">";
|
||||
usageColumn.push(usageText);
|
||||
descriptionColumn.push(getDiagnosticText(Diagnostics.Insert_command_line_options_and_files_from_a_file));
|
||||
marginLength = Math.max(usageText.length, marginLength);
|
||||
|
||||
// Print out each row, aligning all the descriptions on the same column.
|
||||
for (var i = 0; i < usageColumn.length; i++) {
|
||||
var usage = usageColumn[i];
|
||||
var description = descriptionColumn[i];
|
||||
for (let i = 0; i < usageColumn.length; i++) {
|
||||
let usage = usageColumn[i];
|
||||
let description = descriptionColumn[i];
|
||||
output += usage + makePadding(marginLength - usage.length + 2) + description + sys.newLine;
|
||||
}
|
||||
|
||||
|
||||
@@ -273,7 +273,7 @@ namespace ts {
|
||||
// Module references
|
||||
ExternalModuleReference,
|
||||
|
||||
//JSX
|
||||
// JSX
|
||||
JsxElement,
|
||||
JsxSelfClosingElement,
|
||||
JsxOpeningElement,
|
||||
@@ -405,10 +405,10 @@ namespace ts {
|
||||
|
||||
// Context flags set directly by the parser.
|
||||
ParserGeneratedFlags = DisallowIn | Yield | Decorator | ThisNodeHasError | Await,
|
||||
|
||||
|
||||
// Exclude these flags when parsing a Type
|
||||
TypeExcludesFlags = Yield | Await,
|
||||
|
||||
TypeExcludesFlags = Yield | Await,
|
||||
|
||||
// Context flags computed by aggregating child flags upwards.
|
||||
|
||||
// Used during incremental parsing to determine if this node or any of its children had an
|
||||
@@ -1055,7 +1055,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export interface ModuleBlock extends Node, Statement {
|
||||
statements: NodeArray<Statement>
|
||||
statements: NodeArray<Statement>;
|
||||
}
|
||||
|
||||
export interface ImportEqualsDeclaration extends Declaration, Statement {
|
||||
@@ -1171,7 +1171,7 @@ namespace ts {
|
||||
|
||||
export interface JSDocTypeReference extends JSDocType {
|
||||
name: EntityName;
|
||||
typeArguments: NodeArray<JSDocType>
|
||||
typeArguments: NodeArray<JSDocType>;
|
||||
}
|
||||
|
||||
export interface JSDocOptionalType extends JSDocType {
|
||||
@@ -1196,8 +1196,8 @@ namespace ts {
|
||||
}
|
||||
|
||||
export interface JSDocRecordMember extends PropertyDeclaration {
|
||||
name: Identifier | LiteralExpression,
|
||||
type?: JSDocType
|
||||
name: Identifier | LiteralExpression;
|
||||
type?: JSDocType;
|
||||
}
|
||||
|
||||
export interface JSDocComment extends Node {
|
||||
@@ -1294,7 +1294,7 @@ namespace ts {
|
||||
|
||||
export interface CancellationToken {
|
||||
isCancellationRequested(): boolean;
|
||||
|
||||
|
||||
/** @throws OperationCanceledException if isCancellationRequested is true */
|
||||
throwIfCancellationRequested(): void;
|
||||
}
|
||||
@@ -1323,7 +1323,7 @@ namespace ts {
|
||||
getSemanticDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[];
|
||||
getDeclarationDiagnostics(sourceFile?: SourceFile, cancellationToken?: CancellationToken): Diagnostic[];
|
||||
|
||||
/**
|
||||
/**
|
||||
* Gets a type checker that can be used to semantically analyze source fils in the program.
|
||||
*/
|
||||
getTypeChecker(): TypeChecker;
|
||||
@@ -1344,15 +1344,15 @@ namespace ts {
|
||||
|
||||
export interface SourceMapSpan {
|
||||
/** Line number in the .js file. */
|
||||
emittedLine: number;
|
||||
emittedLine: number;
|
||||
/** Column number in the .js file. */
|
||||
emittedColumn: number;
|
||||
emittedColumn: number;
|
||||
/** Line number in the .ts file. */
|
||||
sourceLine: number;
|
||||
sourceLine: number;
|
||||
/** Column number in the .ts file. */
|
||||
sourceColumn: number;
|
||||
sourceColumn: number;
|
||||
/** Optional name (index into names array) associated with this span. */
|
||||
nameIndex?: number;
|
||||
nameIndex?: number;
|
||||
/** .ts file (index into sources array) associated with this span */
|
||||
sourceIndex: number;
|
||||
}
|
||||
@@ -1506,7 +1506,7 @@ namespace ts {
|
||||
NotAccessible,
|
||||
CannotBeNamed
|
||||
}
|
||||
|
||||
|
||||
export interface TypePredicate {
|
||||
parameterName: string;
|
||||
parameterIndex: number;
|
||||
@@ -1526,7 +1526,28 @@ namespace ts {
|
||||
|
||||
/* @internal */
|
||||
export interface SymbolAccessiblityResult extends SymbolVisibilityResult {
|
||||
errorModuleName?: string // If the symbol is not visible from module, module's name
|
||||
errorModuleName?: string; // If the symbol is not visible from module, module's name
|
||||
}
|
||||
|
||||
/** Indicates how to serialize the name for a TypeReferenceNode when emitting decorator
|
||||
* metadata */
|
||||
/* @internal */
|
||||
export enum TypeReferenceSerializationKind {
|
||||
Unknown, // The TypeReferenceNode could not be resolved. The type name
|
||||
// should be emitted using a safe fallback.
|
||||
TypeWithConstructSignatureAndValue, // The TypeReferenceNode resolves to a type with a constructor
|
||||
// function that can be reached at runtime (e.g. a `class`
|
||||
// declaration or a `var` declaration for the static side
|
||||
// of a type, such as the global `Promise` type in lib.d.ts).
|
||||
VoidType, // The TypeReferenceNode resolves to a Void-like type.
|
||||
NumberLikeType, // The TypeReferenceNode resolves to a Number-like type.
|
||||
StringLikeType, // The TypeReferenceNode resolves to a String-like type.
|
||||
BooleanType, // The TypeReferenceNode resolves to a Boolean-like type.
|
||||
ArrayLikeType, // The TypeReferenceNode resolves to an Array-like type.
|
||||
ESSymbolType, // The TypeReferenceNode resolves to the ESSymbol type.
|
||||
TypeWithCallSignature, // The TypeReferenceNode resolves to a Function type or a type
|
||||
// with call signatures.
|
||||
ObjectType, // The TypeReferenceNode resolves to any other type.
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
@@ -1552,9 +1573,7 @@ namespace ts {
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): number;
|
||||
getBlockScopedVariableId(node: Identifier): number;
|
||||
getReferencedValueDeclaration(reference: Identifier): Declaration;
|
||||
serializeTypeOfNode(node: Node): string | string[];
|
||||
serializeParameterTypesOfNode(node: Node): (string | string[])[];
|
||||
serializeReturnTypeOfNode(node: Node): string | string[];
|
||||
getTypeReferenceSerializationKind(node: TypeReferenceNode): TypeReferenceSerializationKind;
|
||||
}
|
||||
|
||||
export const enum SymbolFlags {
|
||||
@@ -1637,7 +1656,7 @@ namespace ts {
|
||||
Export = ExportNamespace | ExportType | ExportValue,
|
||||
|
||||
/* @internal */
|
||||
// The set of things we consider semantically classifiable. Used to speed up the LS during
|
||||
// The set of things we consider semantically classifiable. Used to speed up the LS during
|
||||
// classification.
|
||||
Classifiable = Class | Enum | TypeAlias | Interface | TypeParameter | Module,
|
||||
}
|
||||
@@ -1657,7 +1676,7 @@ namespace ts {
|
||||
/* @internal */ constEnumOnlyModule?: boolean; // True if module contains only const enums or other modules with only const enums
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
/* @internal */
|
||||
export interface SymbolLinks {
|
||||
target?: Symbol; // Resolved (non-alias) target of an alias
|
||||
type?: Type; // Type of value symbol
|
||||
@@ -1672,14 +1691,14 @@ namespace ts {
|
||||
isNestedRedeclaration?: boolean; // True if symbol is block scoped redeclaration
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
/* @internal */
|
||||
export interface TransientSymbol extends Symbol, SymbolLinks { }
|
||||
|
||||
export interface SymbolTable {
|
||||
[index: string]: Symbol;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
/* @internal */
|
||||
export const enum NodeCheckFlags {
|
||||
TypeChecked = 0x00000001, // Node has been type checked
|
||||
LexicalThis = 0x00000002, // Lexical 'this' reference
|
||||
@@ -1701,7 +1720,7 @@ namespace ts {
|
||||
LexicalModuleMergesWithClass= 0x00008000, // Instantiated lexical module declaration is merged with a previous class declaration.
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
/* @internal */
|
||||
export interface NodeLinks {
|
||||
resolvedType?: Type; // Cached type of type node
|
||||
resolvedAwaitedType?: Type; // Cached awaited type of type node
|
||||
@@ -1750,17 +1769,17 @@ namespace ts {
|
||||
ContainsObjectLiteral = 0x00400000, // Type is or contains object literal type
|
||||
ESSymbol = 0x00800000, // Type of symbol primitive introduced in ES6
|
||||
|
||||
/* @internal */
|
||||
/* @internal */
|
||||
Intrinsic = Any | String | Number | Boolean | ESSymbol | Void | Undefined | Null,
|
||||
/* @internal */
|
||||
/* @internal */
|
||||
Primitive = String | Number | Boolean | ESSymbol | Void | Undefined | Null | StringLiteral | Enum,
|
||||
StringLike = String | StringLiteral,
|
||||
NumberLike = Number | Enum,
|
||||
ObjectType = Class | Interface | Reference | Tuple | Anonymous,
|
||||
UnionOrIntersection = Union | Intersection,
|
||||
UnionOrIntersection = Union | Intersection,
|
||||
StructuredType = ObjectType | Union | Intersection,
|
||||
/* @internal */
|
||||
RequiresWidening = ContainsUndefinedOrNull | ContainsObjectLiteral
|
||||
/* @internal */
|
||||
RequiresWidening = ContainsUndefinedOrNull | ContainsObjectLiteral
|
||||
}
|
||||
|
||||
// Properties common to all types
|
||||
@@ -1770,7 +1789,7 @@ namespace ts {
|
||||
symbol?: Symbol; // Symbol associated with type (if any)
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
/* @internal */
|
||||
// Intrinsic types (TypeFlags.Intrinsic)
|
||||
export interface IntrinsicType extends Type {
|
||||
intrinsicName: string; // Name of intrinsic type
|
||||
@@ -1903,6 +1922,9 @@ namespace ts {
|
||||
/* @internal */
|
||||
export interface TypeMapper {
|
||||
(t: TypeParameter): Type;
|
||||
context?: InferenceContext; // The inference context this mapper was created from.
|
||||
// Only inference mappers have this set (in createInferenceMapper).
|
||||
// The identity mapper and regular instantiation mappers do not need it.
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
/* @internal */
|
||||
namespace ts {
|
||||
export interface ReferencePathMatchResult {
|
||||
fileReference?: FileReference
|
||||
diagnosticMessage?: DiagnosticMessage
|
||||
isNoDefaultLib?: boolean
|
||||
fileReference?: FileReference;
|
||||
diagnosticMessage?: DiagnosticMessage;
|
||||
isNoDefaultLib?: boolean;
|
||||
}
|
||||
|
||||
export interface SynthesizedNode extends Node {
|
||||
@@ -16,9 +16,11 @@ namespace ts {
|
||||
|
||||
export function getDeclarationOfKind(symbol: Symbol, kind: SyntaxKind): Declaration {
|
||||
let declarations = symbol.declarations;
|
||||
for (let declaration of declarations) {
|
||||
if (declaration.kind === kind) {
|
||||
return declaration;
|
||||
if (declarations) {
|
||||
for (let declaration of declarations) {
|
||||
if (declaration.kind === kind) {
|
||||
return declaration;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +72,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function releaseStringWriter(writer: StringSymbolWriter) {
|
||||
writer.clear()
|
||||
writer.clear();
|
||||
stringWriters.push(writer);
|
||||
}
|
||||
|
||||
@@ -81,7 +83,7 @@ namespace ts {
|
||||
// Returns true if this node contains a parse error anywhere underneath it.
|
||||
export function containsParseError(node: Node): boolean {
|
||||
aggregateChildData(node);
|
||||
return (node.parserContextFlags & ParserContextFlags.ThisNodeOrAnySubNodesHasError) !== 0
|
||||
return (node.parserContextFlags & ParserContextFlags.ThisNodeOrAnySubNodesHasError) !== 0;
|
||||
}
|
||||
|
||||
function aggregateChildData(node: Node): void {
|
||||
@@ -92,7 +94,7 @@ namespace ts {
|
||||
let thisNodeOrAnySubNodesHasError = ((node.parserContextFlags & ParserContextFlags.ThisNodeHasError) !== 0) ||
|
||||
forEachChild(node, containsParseError);
|
||||
|
||||
// If so, mark ourselves accordingly.
|
||||
// If so, mark ourselves accordingly.
|
||||
if (thisNodeOrAnySubNodesHasError) {
|
||||
node.parserContextFlags |= ParserContextFlags.ThisNodeOrAnySubNodesHasError;
|
||||
}
|
||||
@@ -129,13 +131,13 @@ namespace ts {
|
||||
|
||||
// Returns true if this node is missing from the actual source code. 'missing' is different
|
||||
// from 'undefined/defined'. When a node is undefined (which can happen for optional nodes
|
||||
// in the tree), it is definitel missing. HOwever, a node may be defined, but still be
|
||||
// in the tree), it is definitel missing. HOwever, a node may be defined, but still be
|
||||
// missing. This happens whenever the parser knows it needs to parse something, but can't
|
||||
// get anything in the source code that it expects at that location. For example:
|
||||
//
|
||||
// let a: ;
|
||||
//
|
||||
// Here, the Type in the Type-Annotation is not-optional (as there is a colon in the source
|
||||
// Here, the Type in the Type-Annotation is not-optional (as there is a colon in the source
|
||||
// code). So the parser will attempt to parse out a type, and will create an actual node.
|
||||
// However, this node will be 'missing' in the sense that no actual source-code/tokens are
|
||||
// contained within it.
|
||||
@@ -166,7 +168,7 @@ namespace ts {
|
||||
return getTokenPosOfNode(node, sourceFile);
|
||||
}
|
||||
|
||||
return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.decorators.end);
|
||||
return skipTrivia((sourceFile || getSourceFileOfNode(node)).text, node.decorators.end);
|
||||
}
|
||||
|
||||
export function getSourceTextOfNodeFromSourceFile(sourceFile: SourceFile, node: Node, includeTrivia = false): string {
|
||||
@@ -211,7 +213,7 @@ namespace ts {
|
||||
isCatchClauseVariableDeclaration(declaration);
|
||||
}
|
||||
|
||||
// Gets the nearest enclosing block scope container that has the provided node
|
||||
// Gets the nearest enclosing block scope container that has the provided node
|
||||
// as a descendant, that is not the provided node.
|
||||
export function getEnclosingBlockScopeContainer(node: Node): Node {
|
||||
let current = node.parent;
|
||||
@@ -307,7 +309,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
if (errorNode === undefined) {
|
||||
// If we don't have a better node, then just set the error on the first token of
|
||||
// If we don't have a better node, then just set the error on the first token of
|
||||
// construct.
|
||||
return getSpanOfTokenAtPosition(sourceFile, node.pos);
|
||||
}
|
||||
@@ -339,10 +341,10 @@ namespace ts {
|
||||
return node;
|
||||
}
|
||||
|
||||
// Returns the node flags for this node and all relevant parent nodes. This is done so that
|
||||
// Returns the node flags for this node and all relevant parent nodes. This is done so that
|
||||
// nodes like variable declarations and binding elements can returned a view of their flags
|
||||
// that includes the modifiers from their container. i.e. flags like export/declare aren't
|
||||
// stored on the variable declaration directly, but on the containing variable statement
|
||||
// stored on the variable declaration directly, but on the containing variable statement
|
||||
// (if it has one). Similarly, flags for let/const are store on the variable declaration
|
||||
// list. By calling this function, all those flags are combined so that the client can treat
|
||||
// the node as if it actually had those flags.
|
||||
@@ -406,7 +408,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
export let fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/
|
||||
export let fullTripleSlashReferencePathRegEx = /^(\/\/\/\s*<reference\s+path\s*=\s*)('|")(.+?)\2.*?\/>/;
|
||||
|
||||
export function isTypeNode(node: Node): boolean {
|
||||
if (SyntaxKind.FirstTypeNode <= node.kind && node.kind <= SyntaxKind.LastTypeNode) {
|
||||
@@ -566,7 +568,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
export function isVariableLike(node: Node): boolean {
|
||||
export function isVariableLike(node: Node): node is VariableLikeDeclaration {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.BindingElement:
|
||||
@@ -662,7 +664,7 @@ namespace ts {
|
||||
node = node.parent;
|
||||
break;
|
||||
case SyntaxKind.Decorator:
|
||||
// Decorators are always applied outside of the body of a class or method.
|
||||
// Decorators are always applied outside of the body of a class or method.
|
||||
if (node.parent.kind === SyntaxKind.Parameter && isClassElement(node.parent.parent)) {
|
||||
// If the decorator's parent is a Parameter, we resolve the this container from
|
||||
// the grandparent class declaration.
|
||||
@@ -717,7 +719,7 @@ namespace ts {
|
||||
node = node.parent;
|
||||
break;
|
||||
case SyntaxKind.Decorator:
|
||||
// Decorators are always applied outside of the body of a class or method.
|
||||
// Decorators are always applied outside of the body of a class or method.
|
||||
if (node.parent.kind === SyntaxKind.Parameter && isClassElement(node.parent.parent)) {
|
||||
// If the decorator's parent is a Parameter, we resolve the this container from
|
||||
// the grandparent class declaration.
|
||||
@@ -746,14 +748,14 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function getEntityNameFromTypeNode(node: TypeNode): EntityName | Expression {
|
||||
if (node) {
|
||||
if (node) {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.TypeReference:
|
||||
return (<TypeReferenceNode>node).typeName;
|
||||
case SyntaxKind.ExpressionWithTypeArguments:
|
||||
return (<ExpressionWithTypeArguments>node).expression
|
||||
return (<ExpressionWithTypeArguments>node).expression;
|
||||
case SyntaxKind.Identifier:
|
||||
case SyntaxKind.QualifiedName:
|
||||
return (<EntityName><Node>node);
|
||||
@@ -767,7 +769,7 @@ namespace ts {
|
||||
if (node.kind === SyntaxKind.TaggedTemplateExpression) {
|
||||
return (<TaggedTemplateExpression>node).tag;
|
||||
}
|
||||
|
||||
|
||||
// Will either be a CallExpression, NewExpression, or Decorator.
|
||||
return (<CallExpression | Decorator>node).expression;
|
||||
}
|
||||
@@ -949,7 +951,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function isInstantiatedModule(node: ModuleDeclaration, preserveConstEnums: boolean) {
|
||||
let moduleState = getModuleInstanceState(node)
|
||||
let moduleState = getModuleInstanceState(node);
|
||||
return moduleState === ModuleInstanceState.Instantiated ||
|
||||
(preserveConstEnums && moduleState === ModuleInstanceState.ConstEnumOnly);
|
||||
}
|
||||
@@ -1031,7 +1033,7 @@ namespace ts {
|
||||
|
||||
export function getCorrespondingJSDocParameterTag(parameter: ParameterDeclaration): JSDocParameterTag {
|
||||
if (parameter.name && parameter.name.kind === SyntaxKind.Identifier) {
|
||||
// If it's a parameter, see if the parent has a jsdoc comment with an @param
|
||||
// If it's a parameter, see if the parent has a jsdoc comment with an @param
|
||||
// annotation.
|
||||
let parameterName = (<Identifier>parameter.name).text;
|
||||
|
||||
@@ -1301,7 +1303,7 @@ namespace ts {
|
||||
if (isNoDefaultLibRegEx.exec(comment)) {
|
||||
return {
|
||||
isNoDefaultLib: true
|
||||
}
|
||||
};
|
||||
}
|
||||
else {
|
||||
let matchResult = fullTripleSlashReferencePathRegEx.exec(comment);
|
||||
@@ -1417,7 +1419,7 @@ namespace ts {
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
export function nodeStartsNewLexicalEnvironment(n: Node): boolean {
|
||||
return isFunctionLike(n) || n.kind === SyntaxKind.ModuleDeclaration || n.kind === SyntaxKind.SourceFile;
|
||||
}
|
||||
@@ -1433,7 +1435,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function createSynthesizedNodeArray(): NodeArray<any> {
|
||||
var array = <NodeArray<any>>[];
|
||||
let array = <NodeArray<any>>[];
|
||||
array.pos = -1;
|
||||
array.end = -1;
|
||||
return array;
|
||||
@@ -1517,7 +1519,7 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// This consists of the first 19 unprintable ASCII characters, canonical escapes, lineSeparator,
|
||||
// paragraphSeparator, and nextLine. The latter three are just desirable to suppress new lines in
|
||||
// the language service. These characters should be escaped when printing, and if any characters are added,
|
||||
@@ -1704,6 +1706,10 @@ namespace ts {
|
||||
});
|
||||
}
|
||||
|
||||
export function getSetAccessorTypeAnnotationNode(accessor: AccessorDeclaration): TypeNode {
|
||||
return accessor && accessor.parameters.length > 0 && accessor.parameters[0].type;
|
||||
}
|
||||
|
||||
export function shouldEmitToOwnFile(sourceFile: SourceFile, compilerOptions: CompilerOptions): boolean {
|
||||
if (!isDeclarationFile(sourceFile)) {
|
||||
if ((isExternalModule(sourceFile) || !compilerOptions.out)) {
|
||||
@@ -1969,12 +1975,23 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function isRightSideOfQualifiedNameOrPropertyAccess(node: Node) {
|
||||
return (node.parent.kind === SyntaxKind.QualifiedName && (<QualifiedName>node.parent).right === node) ||
|
||||
(node.parent.kind === SyntaxKind.PropertyAccessExpression && (<PropertyAccessExpression>node.parent).name === node);
|
||||
}
|
||||
|
||||
export function isEmptyObjectLiteralOrArrayLiteral(expression: Node): boolean {
|
||||
let kind = expression.kind;
|
||||
if (kind === SyntaxKind.ObjectLiteralExpression) {
|
||||
return (<ObjectLiteralExpression>expression).properties.length === 0;
|
||||
}
|
||||
if (kind === SyntaxKind.ArrayLiteralExpression) {
|
||||
return (<ArrayLiteralExpression>expression).elements.length === 0;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
export function getLocalSymbolForExportDefault(symbol: Symbol) {
|
||||
return symbol && symbol.valueDeclaration && (symbol.valueDeclaration.flags & NodeFlags.Default) ? symbol.valueDeclaration.localSymbol : undefined;
|
||||
}
|
||||
@@ -1988,7 +2005,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace each instance of non-ascii characters by one, two, three, or four escape sequences
|
||||
* Replace each instance of non-ascii characters by one, two, three, or four escape sequences
|
||||
* representing the UTF-8 encoding of the character, and return the expanded char code list.
|
||||
*/
|
||||
function getExpandedCharCodes(input: string): number[] {
|
||||
@@ -2031,7 +2048,7 @@ namespace ts {
|
||||
* Converts a string to a base-64 encoded ASCII string.
|
||||
*/
|
||||
export function convertToBase64(input: string): string {
|
||||
var result = "";
|
||||
let result = "";
|
||||
let charCodes = getExpandedCharCodes(input);
|
||||
let i = 0;
|
||||
let length = charCodes.length;
|
||||
@@ -2073,7 +2090,7 @@ namespace ts {
|
||||
return lineFeed;
|
||||
}
|
||||
else if (sys) {
|
||||
return sys.newLine
|
||||
return sys.newLine;
|
||||
}
|
||||
return carriageReturnLineFeed;
|
||||
}
|
||||
@@ -2085,11 +2102,11 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function textSpanEnd(span: TextSpan) {
|
||||
return span.start + span.length
|
||||
return span.start + span.length;
|
||||
}
|
||||
|
||||
export function textSpanIsEmpty(span: TextSpan) {
|
||||
return span.length === 0
|
||||
return span.length === 0;
|
||||
}
|
||||
|
||||
export function textSpanContainsPosition(span: TextSpan, position: number) {
|
||||
@@ -2117,7 +2134,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
export function textSpanIntersectsWithTextSpan(span: TextSpan, other: TextSpan) {
|
||||
return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start
|
||||
return other.start <= textSpanEnd(span) && textSpanEnd(other) >= span.start;
|
||||
}
|
||||
|
||||
export function textSpanIntersectsWith(span: TextSpan, start: number, length: number) {
|
||||
@@ -2178,10 +2195,10 @@ namespace ts {
|
||||
export let unchangedTextChangeRange = createTextChangeRange(createTextSpan(0, 0), 0);
|
||||
|
||||
/**
|
||||
* Called to merge all the changes that occurred across several versions of a script snapshot
|
||||
* Called to merge all the changes that occurred across several versions of a script snapshot
|
||||
* into a single change. i.e. if a user keeps making successive edits to a script we will
|
||||
* have a text change from V1 to V2, V2 to V3, ..., Vn.
|
||||
*
|
||||
* have a text change from V1 to V2, V2 to V3, ..., Vn.
|
||||
*
|
||||
* This function will then merge those changes into a single change range valid between V1 and
|
||||
* Vn.
|
||||
*/
|
||||
@@ -2212,17 +2229,17 @@ namespace ts {
|
||||
//
|
||||
// 0 10 20 30 40 50 60 70 80 90 100
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
// | /
|
||||
// | /----
|
||||
// T1 | /----
|
||||
// | /----
|
||||
// | /----
|
||||
// | /
|
||||
// | /----
|
||||
// T1 | /----
|
||||
// | /----
|
||||
// | /----
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
// | \
|
||||
// | \
|
||||
// T2 | \
|
||||
// | \
|
||||
// | \
|
||||
// | \
|
||||
// | \
|
||||
// T2 | \
|
||||
// | \
|
||||
// | \
|
||||
// -------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// Merging these turns out to not be too difficult. First, determining the new start of the change is trivial
|
||||
@@ -2230,17 +2247,17 @@ namespace ts {
|
||||
//
|
||||
// 0 10 20 30 40 50 60 70 80 90 100
|
||||
// ------------------------------------------------------------*------------------------------------------
|
||||
// | /
|
||||
// | /----
|
||||
// T1 | /----
|
||||
// | /----
|
||||
// | /----
|
||||
// | /
|
||||
// | /----
|
||||
// T1 | /----
|
||||
// | /----
|
||||
// | /----
|
||||
// ----------------------------------------$-------------------$------------------------------------------
|
||||
// . | \
|
||||
// . | \
|
||||
// T2 . | \
|
||||
// . | \
|
||||
// . | \
|
||||
// . | \
|
||||
// . | \
|
||||
// T2 . | \
|
||||
// . | \
|
||||
// . | \
|
||||
// ----------------------------------------------------------------------*--------------------------------
|
||||
//
|
||||
// (Note the dots represent the newly inferrred start.
|
||||
@@ -2251,22 +2268,22 @@ namespace ts {
|
||||
//
|
||||
// 0 10 20 30 40 50 60 70 80 90 100
|
||||
// --------------------------------------------------------------------------------*----------------------
|
||||
// | /
|
||||
// | /----
|
||||
// T1 | /----
|
||||
// | /----
|
||||
// | /----
|
||||
// | /
|
||||
// | /----
|
||||
// T1 | /----
|
||||
// | /----
|
||||
// | /----
|
||||
// ------------------------------------------------------------$------------------------------------------
|
||||
// . | \
|
||||
// . | \
|
||||
// T2 . | \
|
||||
// . | \
|
||||
// . | \
|
||||
// . | \
|
||||
// . | \
|
||||
// T2 . | \
|
||||
// . | \
|
||||
// . | \
|
||||
// ----------------------------------------------------------------------*--------------------------------
|
||||
//
|
||||
// In other words (in this case), we're recognizing that the second edit happened after where the first edit
|
||||
// ended with a delta of 20 characters (60 - 40). Thus, if we go back in time to where the first edit started
|
||||
// that's the same as if we started at char 80 instead of 60.
|
||||
// that's the same as if we started at char 80 instead of 60.
|
||||
//
|
||||
// As it so happens, the same logic applies if the second edit precedes the first edit. In that case rahter
|
||||
// than pusing the first edit forward to match the second, we'll push the second edit forward to match the
|
||||
@@ -2276,7 +2293,7 @@ namespace ts {
|
||||
// semantics: { { start: 10, length: 70 }, newLength: 60 }
|
||||
//
|
||||
// The math then works out as follows.
|
||||
// If we have { oldStart1, oldEnd1, newEnd1 } and { oldStart2, oldEnd2, newEnd2 } then we can compute the
|
||||
// If we have { oldStart1, oldEnd1, newEnd1 } and { oldStart2, oldEnd2, newEnd2 } then we can compute the
|
||||
// final result like so:
|
||||
//
|
||||
// {
|
||||
|
||||
Reference in New Issue
Block a user