mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Merge branch 'master' into limit-recursive-structured-type-resolution
This commit is contained in:
@@ -749,6 +749,10 @@ namespace ts {
|
||||
return expr1.kind === SyntaxKind.TypeOfExpression && isNarrowableOperand((<TypeOfExpression>expr1).expression) && expr2.kind === SyntaxKind.StringLiteral;
|
||||
}
|
||||
|
||||
function isNarrowableInOperands(left: Expression, right: Expression) {
|
||||
return left.kind === SyntaxKind.StringLiteral && isNarrowingExpression(right);
|
||||
}
|
||||
|
||||
function isNarrowingBinaryExpression(expr: BinaryExpression) {
|
||||
switch (expr.operatorToken.kind) {
|
||||
case SyntaxKind.EqualsToken:
|
||||
@@ -761,6 +765,8 @@ namespace ts {
|
||||
isNarrowingTypeofOperands(expr.right, expr.left) || isNarrowingTypeofOperands(expr.left, expr.right);
|
||||
case SyntaxKind.InstanceOfKeyword:
|
||||
return isNarrowableOperand(expr.left);
|
||||
case SyntaxKind.InKeyword:
|
||||
return isNarrowableInOperands(expr.left, expr.right);
|
||||
case SyntaxKind.CommaToken:
|
||||
return isNarrowingExpression(expr.right);
|
||||
}
|
||||
|
||||
@@ -468,9 +468,9 @@ namespace ts {
|
||||
}
|
||||
|
||||
function getReferencedByPaths(referencedFilePath: Path) {
|
||||
return mapDefinedIter(references.entries(), ([filePath, referencesInFile]) =>
|
||||
return arrayFrom(mapDefinedIterator(references.entries(), ([filePath, referencesInFile]) =>
|
||||
referencesInFile.has(referencedFilePath) ? filePath as Path : undefined
|
||||
);
|
||||
));
|
||||
}
|
||||
|
||||
function getFilesAffectedByUpdatedShape(program: Program, sourceFile: SourceFile): ReadonlyArray<SourceFile> {
|
||||
@@ -504,7 +504,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Return array of values that needs emit
|
||||
return flatMapIter(seenFileNamesMap.values(), value => value);
|
||||
return arrayFrom(mapDefinedIterator(seenFileNamesMap.values(), value => value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+491
-288
File diff suppressed because it is too large
Load Diff
@@ -82,12 +82,13 @@ namespace ts {
|
||||
es2015: ScriptTarget.ES2015,
|
||||
es2016: ScriptTarget.ES2016,
|
||||
es2017: ScriptTarget.ES2017,
|
||||
es2018: ScriptTarget.ES2018,
|
||||
esnext: ScriptTarget.ESNext,
|
||||
}),
|
||||
paramType: Diagnostics.VERSION,
|
||||
showInSimplifiedHelpView: true,
|
||||
category: Diagnostics.Basic_Options,
|
||||
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_ES2015_ES2016_ES2017_or_ESNEXT,
|
||||
description: Diagnostics.Specify_ECMAScript_target_version_Colon_ES3_default_ES5_ES2015_ES2016_ES2017_ES2018_or_ESNEXT,
|
||||
},
|
||||
{
|
||||
name: "module",
|
||||
@@ -120,6 +121,7 @@ namespace ts {
|
||||
"es7": "lib.es2016.d.ts",
|
||||
"es2016": "lib.es2016.d.ts",
|
||||
"es2017": "lib.es2017.d.ts",
|
||||
"es2018": "lib.es2018.d.ts",
|
||||
"esnext": "lib.esnext.d.ts",
|
||||
// Host only
|
||||
"dom": "lib.dom.d.ts",
|
||||
@@ -709,12 +711,11 @@ namespace ts {
|
||||
export function convertEnableAutoDiscoveryToEnable(typeAcquisition: TypeAcquisition): TypeAcquisition {
|
||||
// Convert deprecated typingOptions.enableAutoDiscovery to typeAcquisition.enable
|
||||
if (typeAcquisition && typeAcquisition.enableAutoDiscovery !== undefined && typeAcquisition.enable === undefined) {
|
||||
const result: TypeAcquisition = {
|
||||
return {
|
||||
enable: typeAcquisition.enableAutoDiscovery,
|
||||
include: typeAcquisition.include || [],
|
||||
exclude: typeAcquisition.exclude || []
|
||||
};
|
||||
return result;
|
||||
}
|
||||
return typeAcquisition;
|
||||
}
|
||||
@@ -1797,9 +1798,8 @@ namespace ts {
|
||||
return options;
|
||||
}
|
||||
|
||||
function getDefaultTypeAcquisition(configFileName?: string) {
|
||||
const options: TypeAcquisition = { enable: getBaseFileName(configFileName) === "jsconfig.json", include: [], exclude: [] };
|
||||
return options;
|
||||
function getDefaultTypeAcquisition(configFileName?: string): TypeAcquisition {
|
||||
return { enable: getBaseFileName(configFileName) === "jsconfig.json", include: [], exclude: [] };
|
||||
}
|
||||
|
||||
function convertTypeAcquisitionFromJsonWorker(jsonOptions: any,
|
||||
@@ -1906,21 +1906,6 @@ namespace ts {
|
||||
*/
|
||||
const invalidTrailingRecursionPattern = /(^|\/)\*\*\/?$/;
|
||||
|
||||
/**
|
||||
* Tests for a path with multiple recursive directory wildcards.
|
||||
* Matches **\** and **\a\**, but not **\a**b.
|
||||
*
|
||||
* NOTE: used \ in place of / above to avoid issues with multiline comments.
|
||||
*
|
||||
* Breakdown:
|
||||
* (^|\/) # matches either the beginning of the string or a directory separator.
|
||||
* \*\*\/ # matches a recursive directory wildcard "**" followed by a directory separator.
|
||||
* (.*\/)? # optionally matches any number of characters followed by a directory separator.
|
||||
* \*\* # matches a recursive directory wildcard "**"
|
||||
* ($|\/) # matches either the end of the string or a directory separator.
|
||||
*/
|
||||
const invalidMultipleRecursionPatterns = /(^|\/)\*\*\/(.*\/)?\*\*($|\/)/;
|
||||
|
||||
/**
|
||||
* Tests for a path where .. appears after a recursive directory wildcard.
|
||||
* Matches **\..\*, **\a\..\*, and **\.., but not ..\**\*
|
||||
@@ -2115,9 +2100,6 @@ namespace ts {
|
||||
if (!allowTrailingRecursion && invalidTrailingRecursionPattern.test(spec)) {
|
||||
return Diagnostics.File_specification_cannot_end_in_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0;
|
||||
}
|
||||
else if (invalidMultipleRecursionPatterns.test(spec)) {
|
||||
return Diagnostics.File_specification_cannot_contain_multiple_recursive_directory_wildcards_Asterisk_Asterisk_Colon_0;
|
||||
}
|
||||
else if (invalidDotDotAfterRecursiveWildcardPattern.test(spec)) {
|
||||
return Diagnostics.File_specification_cannot_contain_a_parent_directory_that_appears_after_a_recursive_directory_wildcard_Asterisk_Asterisk_Colon_0;
|
||||
}
|
||||
|
||||
+82
-38
@@ -191,6 +191,19 @@ namespace ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function firstDefinedIterator<T, U>(iter: Iterator<T>, callback: (element: T) => U | undefined): U | undefined {
|
||||
while (true) {
|
||||
const { value, done } = iter.next();
|
||||
if (done) {
|
||||
return undefined;
|
||||
}
|
||||
const result = callback(value);
|
||||
if (result !== undefined) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterates through the parent chain of a node and performs the callback on each parent until the callback
|
||||
* returns a truthy value, then returns that value.
|
||||
@@ -215,13 +228,27 @@ namespace ts {
|
||||
|
||||
export function zipWith<T, U, V>(arrayA: ReadonlyArray<T>, arrayB: ReadonlyArray<U>, callback: (a: T, b: U, index: number) => V): V[] {
|
||||
const result: V[] = [];
|
||||
Debug.assert(arrayA.length === arrayB.length);
|
||||
Debug.assertEqual(arrayA.length, arrayB.length);
|
||||
for (let i = 0; i < arrayA.length; i++) {
|
||||
result.push(callback(arrayA[i], arrayB[i], i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
export function zipToIterator<T, U>(arrayA: ReadonlyArray<T>, arrayB: ReadonlyArray<U>): Iterator<[T, U]> {
|
||||
Debug.assertEqual(arrayA.length, arrayB.length);
|
||||
let i = 0;
|
||||
return {
|
||||
next() {
|
||||
if (i === arrayA.length) {
|
||||
return { value: undefined as never, done: true };
|
||||
}
|
||||
i++;
|
||||
return { value: [arrayA[i - 1], arrayB[i - 1]], done: false };
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function zipToMap<T>(keys: ReadonlyArray<string>, values: ReadonlyArray<T>): Map<T> {
|
||||
Debug.assert(keys.length === values.length);
|
||||
const map = createMap<T>();
|
||||
@@ -261,6 +288,8 @@ namespace ts {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function findLast<T, U extends T>(array: ReadonlyArray<T>, predicate: (element: T, index: number) => element is U): U | undefined;
|
||||
export function findLast<T>(array: ReadonlyArray<T>, predicate: (element: T, index: number) => boolean): T | undefined;
|
||||
export function findLast<T>(array: ReadonlyArray<T>, predicate: (element: T, index: number) => boolean): T | undefined {
|
||||
for (let i = array.length - 1; i >= 0; i--) {
|
||||
const value = array[i];
|
||||
@@ -474,22 +503,32 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function flatMapIter<T, U>(iter: Iterator<T>, mapfn: (x: T) => U | U[] | undefined): U[] {
|
||||
const result: U[] = [];
|
||||
while (true) {
|
||||
const { value, done } = iter.next();
|
||||
if (done) break;
|
||||
const res = mapfn(value);
|
||||
if (res) {
|
||||
if (isArray(res)) {
|
||||
result.push(...res);
|
||||
export function flatMapIterator<T, U>(iter: Iterator<T>, mapfn: (x: T) => U[] | Iterator<U> | undefined): Iterator<U> {
|
||||
const first = iter.next();
|
||||
if (first.done) {
|
||||
return emptyIterator;
|
||||
}
|
||||
let currentIter = getIterator(first.value);
|
||||
return {
|
||||
next() {
|
||||
while (true) {
|
||||
const currentRes = currentIter.next();
|
||||
if (!currentRes.done) {
|
||||
return currentRes;
|
||||
}
|
||||
const iterRes = iter.next();
|
||||
if (iterRes.done) {
|
||||
return iterRes;
|
||||
}
|
||||
currentIter = getIterator(iterRes.value);
|
||||
}
|
||||
else {
|
||||
result.push(res);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
function getIterator(x: T): Iterator<U> {
|
||||
const res = mapfn(x);
|
||||
return res === undefined ? emptyIterator : isArray(res) ? arrayIterator(res) : res;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -537,17 +576,34 @@ namespace ts {
|
||||
return result;
|
||||
}
|
||||
|
||||
export function mapDefinedIter<T, U>(iter: Iterator<T>, mapFn: (x: T) => U | undefined): U[] {
|
||||
const result: U[] = [];
|
||||
while (true) {
|
||||
const { value, done } = iter.next();
|
||||
if (done) break;
|
||||
const res = mapFn(value);
|
||||
if (res !== undefined) {
|
||||
result.push(res);
|
||||
export function mapDefinedIterator<T, U>(iter: Iterator<T>, mapFn: (x: T) => U | undefined): Iterator<U> {
|
||||
return {
|
||||
next() {
|
||||
while (true) {
|
||||
const res = iter.next();
|
||||
if (res.done) {
|
||||
return res;
|
||||
}
|
||||
const value = mapFn(res.value);
|
||||
if (value !== undefined) {
|
||||
return { value, done: false };
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
export const emptyIterator: Iterator<never> = { next: () => ({ value: undefined as never, done: true }) };
|
||||
|
||||
export function singleIterator<T>(value: T): Iterator<T> {
|
||||
let done = false;
|
||||
return {
|
||||
next() {
|
||||
const wasDone = done;
|
||||
done = true;
|
||||
return wasDone ? { value: undefined as never, done: true } : { value, done: false };
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1345,7 +1401,6 @@ namespace ts {
|
||||
this.set(key, values = [value]);
|
||||
}
|
||||
return values;
|
||||
|
||||
}
|
||||
function multiMapRemove<T>(this: MultiMap<T>, key: string, value: T) {
|
||||
const values = this.get(key);
|
||||
@@ -1360,7 +1415,7 @@ namespace ts {
|
||||
/**
|
||||
* Tests whether a value is an array.
|
||||
*/
|
||||
export function isArray(value: any): value is ReadonlyArray<any> {
|
||||
export function isArray(value: any): value is ReadonlyArray<{}> {
|
||||
return Array.isArray ? Array.isArray(value) : value instanceof Array;
|
||||
}
|
||||
|
||||
@@ -1939,11 +1994,6 @@ namespace ts {
|
||||
return /^\.\.?($|[\\/])/.test(path);
|
||||
}
|
||||
|
||||
/** @deprecated Use `!isExternalModuleNameRelative(moduleName)` instead. */
|
||||
export function moduleHasNonRelativeName(moduleName: string): boolean {
|
||||
return !isExternalModuleNameRelative(moduleName);
|
||||
}
|
||||
|
||||
export function getEmitScriptTarget(compilerOptions: CompilerOptions) {
|
||||
return compilerOptions.target || ScriptTarget.ES3;
|
||||
}
|
||||
@@ -2326,7 +2376,6 @@ namespace ts {
|
||||
|
||||
function getSubPatternFromSpec(spec: string, basePath: string, usage: "files" | "directories" | "exclude", { singleAsteriskRegexFragment, doubleAsteriskRegexFragment, replaceWildcardCharacter }: WildcardMatcher): string | undefined {
|
||||
let subpattern = "";
|
||||
let hasRecursiveDirectoryWildcard = false;
|
||||
let hasWrittenComponent = false;
|
||||
const components = getNormalizedPathComponents(spec, basePath);
|
||||
const lastComponent = lastOrUndefined(components);
|
||||
@@ -2345,12 +2394,7 @@ namespace ts {
|
||||
let optionalCount = 0;
|
||||
for (let component of components) {
|
||||
if (component === "**") {
|
||||
if (hasRecursiveDirectoryWildcard) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
subpattern += doubleAsteriskRegexFragment;
|
||||
hasRecursiveDirectoryWildcard = true;
|
||||
}
|
||||
else {
|
||||
if (usage === "directories") {
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace ts {
|
||||
let currentIdentifiers: Map<string>;
|
||||
let isCurrentFileExternalModule: boolean;
|
||||
let reportedDeclarationError = false;
|
||||
let errorNameNode: DeclarationName;
|
||||
let errorNameNode: DeclarationName | QualifiedName;
|
||||
const emitJsDocComments = compilerOptions.removeComments ? noop : writeJsDocComments;
|
||||
const emit = compilerOptions.stripInternal ? stripInternal : emitNode;
|
||||
let needsDeclare = true;
|
||||
@@ -1372,7 +1372,7 @@ namespace ts {
|
||||
// if this is property of type literal,
|
||||
// or is parameter of method/call/construct/index signature of type literal
|
||||
// emit only if type is specified
|
||||
if (node.type) {
|
||||
if (hasType(node)) {
|
||||
write(": ");
|
||||
emitType(node.type);
|
||||
}
|
||||
|
||||
@@ -2272,6 +2272,14 @@
|
||||
"category": "Error",
|
||||
"code": 2718
|
||||
},
|
||||
"Type '{0}' is not assignable to type '{1}'. Two different types with this name exist, but they are unrelated.": {
|
||||
"category": "Error",
|
||||
"code": 2719
|
||||
},
|
||||
"Class '{0}' incorrectly implements class '{1}'. Did you mean to extend '{1}' and inherit its members as a subclass?": {
|
||||
"category": "Error",
|
||||
"code": 2720
|
||||
},
|
||||
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
@@ -2619,10 +2627,6 @@
|
||||
"category": "Error",
|
||||
"code": 5010
|
||||
},
|
||||
"File specification cannot contain multiple recursive directory wildcards ('**'): '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 5011
|
||||
},
|
||||
"Cannot read file '{0}': {1}.": {
|
||||
"category": "Error",
|
||||
"code": 5012
|
||||
@@ -2719,6 +2723,11 @@
|
||||
"category": "Error",
|
||||
"code": 5067
|
||||
},
|
||||
"Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.": {
|
||||
"category": "Error",
|
||||
"code": 5068
|
||||
},
|
||||
|
||||
"Concatenate and emit output to single file.": {
|
||||
"category": "Message",
|
||||
"code": 6001
|
||||
@@ -2771,7 +2780,7 @@
|
||||
"category": "Message",
|
||||
"code": 6013
|
||||
},
|
||||
"Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', or 'ESNEXT'.": {
|
||||
"Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'.": {
|
||||
"category": "Message",
|
||||
"code": 6015
|
||||
},
|
||||
@@ -2819,6 +2828,10 @@
|
||||
"category": "Message",
|
||||
"code": 6030
|
||||
},
|
||||
"Starting compilation in watch mode...": {
|
||||
"category": "Message",
|
||||
"code": 6031
|
||||
},
|
||||
"File change detected. Starting incremental compilation...": {
|
||||
"category": "Message",
|
||||
"code": 6032
|
||||
@@ -3407,6 +3420,14 @@
|
||||
"category": "Message",
|
||||
"code": 6187
|
||||
},
|
||||
"Numeric separators are not allowed here.": {
|
||||
"category": "Error",
|
||||
"code": 6188
|
||||
},
|
||||
"Multiple consecutive numeric separators are not permitted.": {
|
||||
"category": "Error",
|
||||
"code": 6189
|
||||
},
|
||||
"Variable '{0}' implicitly has an '{1}' type.": {
|
||||
"category": "Error",
|
||||
"code": 7005
|
||||
@@ -3710,7 +3731,7 @@
|
||||
},
|
||||
"JSX fragment is not supported when using --jsxFactory": {
|
||||
"category": "Error",
|
||||
"code":17016
|
||||
"code": 17016
|
||||
},
|
||||
|
||||
"Circularity detected while resolving configuration: {0}": {
|
||||
@@ -3730,104 +3751,95 @@
|
||||
"code": 18003
|
||||
},
|
||||
|
||||
"Add missing 'super()' call.": {
|
||||
"Add missing 'super()' call": {
|
||||
"category": "Message",
|
||||
"code": 90001
|
||||
},
|
||||
"Make 'super()' call the first statement in the constructor.": {
|
||||
"Make 'super()' call the first statement in the constructor": {
|
||||
"category": "Message",
|
||||
"code": 90002
|
||||
},
|
||||
"Change 'extends' to 'implements'.": {
|
||||
"Change 'extends' to 'implements'": {
|
||||
"category": "Message",
|
||||
"code": 90003
|
||||
},
|
||||
"Remove declaration for: '{0}'.": {
|
||||
"Remove declaration for: '{0}'": {
|
||||
"category": "Message",
|
||||
"code": 90004
|
||||
},
|
||||
"Implement interface '{0}'.": {
|
||||
"Implement interface '{0}'": {
|
||||
"category": "Message",
|
||||
"code": 90006
|
||||
},
|
||||
"Implement inherited abstract class.": {
|
||||
"Implement inherited abstract class": {
|
||||
"category": "Message",
|
||||
"code": 90007
|
||||
},
|
||||
"Add 'this.' to unresolved variable.": {
|
||||
"Add 'this.' to unresolved variable": {
|
||||
"category": "Message",
|
||||
"code": 90008
|
||||
},
|
||||
"Adding a tsconfig.json file will help organize projects that contain both TypeScript and JavaScript files. Learn more at https://aka.ms/tsconfig.": {
|
||||
"category": "Error",
|
||||
"code": 90009
|
||||
},
|
||||
"Type '{0}' is not assignable to type '{1}'. Two different types with this name exist, but they are unrelated.": {
|
||||
"category": "Error",
|
||||
"code": 90010
|
||||
},
|
||||
"Import '{0}' from module \"{1}\".": {
|
||||
"Import '{0}' from module \"{1}\"": {
|
||||
"category": "Message",
|
||||
"code": 90013
|
||||
},
|
||||
"Change '{0}' to '{1}'.": {
|
||||
"Change '{0}' to '{1}'": {
|
||||
"category": "Message",
|
||||
"code": 90014
|
||||
},
|
||||
"Add '{0}' to existing import declaration from \"{1}\".": {
|
||||
"Add '{0}' to existing import declaration from \"{1}\"": {
|
||||
"category": "Message",
|
||||
"code": 90015
|
||||
},
|
||||
"Declare property '{0}'.": {
|
||||
"Declare property '{0}'": {
|
||||
"category": "Message",
|
||||
"code": 90016
|
||||
},
|
||||
"Add index signature for property '{0}'.": {
|
||||
"Add index signature for property '{0}'": {
|
||||
"category": "Message",
|
||||
"code": 90017
|
||||
},
|
||||
|
||||
"Disable checking for this file.": {
|
||||
"Disable checking for this file": {
|
||||
"category": "Message",
|
||||
"code": 90018
|
||||
},
|
||||
"Ignore this error message.": {
|
||||
"Ignore this error message": {
|
||||
"category": "Message",
|
||||
"code": 90019
|
||||
},
|
||||
"Initialize property '{0}' in the constructor.": {
|
||||
"Initialize property '{0}' in the constructor": {
|
||||
"category": "Message",
|
||||
"code": 90020
|
||||
},
|
||||
"Initialize static property '{0}'.": {
|
||||
"Initialize static property '{0}'": {
|
||||
"category": "Message",
|
||||
"code": 90021
|
||||
},
|
||||
"Change spelling to '{0}'.": {
|
||||
"Change spelling to '{0}'": {
|
||||
"category": "Message",
|
||||
"code": 90022
|
||||
},
|
||||
"Declare method '{0}'.": {
|
||||
"Declare method '{0}'": {
|
||||
"category": "Message",
|
||||
"code": 90023
|
||||
},
|
||||
"Declare static method '{0}'.": {
|
||||
"Declare static method '{0}'": {
|
||||
"category": "Message",
|
||||
"code": 90024
|
||||
},
|
||||
"Prefix '{0}' with an underscore.": {
|
||||
"Prefix '{0}' with an underscore": {
|
||||
"category": "Message",
|
||||
"code": 90025
|
||||
},
|
||||
"Rewrite as the indexed access type '{0}'.": {
|
||||
"Rewrite as the indexed access type '{0}'": {
|
||||
"category": "Message",
|
||||
"code": 90026
|
||||
},
|
||||
"Declare static property '{0}'.": {
|
||||
"Declare static property '{0}'": {
|
||||
"category": "Message",
|
||||
"code": 90027
|
||||
},
|
||||
"Call decorator expression.": {
|
||||
"Call decorator expression": {
|
||||
"category": "Message",
|
||||
"code": 90028
|
||||
},
|
||||
@@ -3871,11 +3883,11 @@
|
||||
"category": "Message",
|
||||
"code": 95010
|
||||
},
|
||||
"Infer type of '{0}' from usage.": {
|
||||
"Infer type of '{0}' from usage": {
|
||||
"category": "Message",
|
||||
"code": 95011
|
||||
},
|
||||
"Infer parameter types from usage.": {
|
||||
"Infer parameter types from usage": {
|
||||
"category": "Message",
|
||||
"code": 95012
|
||||
},
|
||||
|
||||
@@ -64,9 +64,9 @@ namespace ts {
|
||||
return { fileName: resolved.path, packageId: resolved.packageId };
|
||||
}
|
||||
|
||||
function createResolvedModuleWithFailedLookupLocations(resolved: Resolved | undefined, isExternalLibraryImport: boolean, failedLookupLocations: string[]): ResolvedModuleWithFailedLookupLocations {
|
||||
function createResolvedModuleWithFailedLookupLocations(resolved: Resolved | undefined, originalPath: string | undefined, isExternalLibraryImport: boolean, failedLookupLocations: string[]): ResolvedModuleWithFailedLookupLocations {
|
||||
return {
|
||||
resolvedModule: resolved && { resolvedFileName: resolved.path, extension: resolved.extension, isExternalLibraryImport, packageId: resolved.packageId },
|
||||
resolvedModule: resolved && { resolvedFileName: resolved.path, originalPath, extension: resolved.extension, isExternalLibraryImport, packageId: resolved.packageId },
|
||||
failedLookupLocations
|
||||
};
|
||||
}
|
||||
@@ -732,12 +732,12 @@ namespace ts {
|
||||
|
||||
const result = jsOnly ? tryResolve(Extensions.JavaScript) : (tryResolve(Extensions.TypeScript) || tryResolve(Extensions.JavaScript));
|
||||
if (result && result.value) {
|
||||
const { resolved, isExternalLibraryImport } = result.value;
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved, isExternalLibraryImport, failedLookupLocations);
|
||||
const { resolved, originalPath, isExternalLibraryImport } = result.value;
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved, originalPath, isExternalLibraryImport, failedLookupLocations);
|
||||
}
|
||||
return { resolvedModule: undefined, failedLookupLocations };
|
||||
|
||||
function tryResolve(extensions: Extensions): SearchResult<{ resolved: Resolved, isExternalLibraryImport: boolean }> {
|
||||
function tryResolve(extensions: Extensions): SearchResult<{ resolved: Resolved, originalPath?: string, isExternalLibraryImport: boolean }> {
|
||||
const loader: ResolutionKindSpecificLoader = (extensions, candidate, failedLookupLocations, onlyRecordFailures, state) => nodeLoadModuleByRelativeName(extensions, candidate, failedLookupLocations, onlyRecordFailures, state, /*considerPackageJson*/ true);
|
||||
const resolved = tryLoadModuleUsingOptionalResolutionSettings(extensions, moduleName, containingDirectory, loader, failedLookupLocations, state);
|
||||
if (resolved) {
|
||||
@@ -752,11 +752,17 @@ namespace ts {
|
||||
if (!resolved) return undefined;
|
||||
|
||||
let resolvedValue = resolved.value;
|
||||
if (!compilerOptions.preserveSymlinks) {
|
||||
resolvedValue = resolvedValue && { ...resolved.value, path: realPath(resolved.value.path, host, traceEnabled), extension: resolved.value.extension };
|
||||
let originalPath: string | undefined;
|
||||
if (!compilerOptions.preserveSymlinks && resolvedValue) {
|
||||
originalPath = resolvedValue.path;
|
||||
const path = realPath(resolved.value.path, host, traceEnabled);
|
||||
if (path === originalPath) {
|
||||
originalPath = undefined;
|
||||
}
|
||||
resolvedValue = { ...resolvedValue, path };
|
||||
}
|
||||
// For node_modules lookups, get the real path so that multiple accesses to an `npm link`-ed module do not create duplicate files.
|
||||
return { value: resolvedValue && { resolved: resolvedValue, isExternalLibraryImport: true } };
|
||||
return { value: resolvedValue && { resolved: resolvedValue, originalPath, isExternalLibraryImport: true } };
|
||||
}
|
||||
else {
|
||||
const { path: candidate, parts } = normalizePathAndParts(combinePaths(containingDirectory, moduleName));
|
||||
@@ -1115,7 +1121,8 @@ namespace ts {
|
||||
const containingDirectory = getDirectoryPath(containingFile);
|
||||
|
||||
const resolved = tryResolve(Extensions.TypeScript) || tryResolve(Extensions.JavaScript);
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved && resolved.value, /*isExternalLibraryImport*/ false, failedLookupLocations);
|
||||
// No originalPath because classic resolution doesn't resolve realPath
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved && resolved.value, /*originalPath*/ undefined, /*isExternalLibraryImport*/ false, failedLookupLocations);
|
||||
|
||||
function tryResolve(extensions: Extensions): SearchResult<Resolved> {
|
||||
const resolvedUsingSettings = tryLoadModuleUsingOptionalResolutionSettings(extensions, moduleName, containingDirectory, loadModuleFromFileNoPackageId, failedLookupLocations, state);
|
||||
@@ -1162,7 +1169,7 @@ namespace ts {
|
||||
const state: ModuleResolutionState = { compilerOptions, host, traceEnabled };
|
||||
const failedLookupLocations: string[] = [];
|
||||
const resolved = loadModuleFromNodeModulesOneLevel(Extensions.DtsOnly, moduleName, globalCache, failedLookupLocations, state);
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved, /*isExternalLibraryImport*/ true, failedLookupLocations);
|
||||
return createResolvedModuleWithFailedLookupLocations(resolved, /*originalPath*/ undefined, /*isExternalLibraryImport*/ true, failedLookupLocations);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+36
-7
@@ -88,20 +88,48 @@ namespace ts {
|
||||
case SyntaxKind.SpreadAssignment:
|
||||
return visitNode(cbNode, (<SpreadAssignment>node).expression);
|
||||
case SyntaxKind.Parameter:
|
||||
return visitNodes(cbNode, cbNodes, node.decorators) ||
|
||||
visitNodes(cbNode, cbNodes, node.modifiers) ||
|
||||
visitNode(cbNode, (<ParameterDeclaration>node).dotDotDotToken) ||
|
||||
visitNode(cbNode, (<ParameterDeclaration>node).name) ||
|
||||
visitNode(cbNode, (<ParameterDeclaration>node).questionToken) ||
|
||||
visitNode(cbNode, (<ParameterDeclaration>node).type) ||
|
||||
visitNode(cbNode, (<ParameterDeclaration>node).initializer);
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
return visitNodes(cbNode, cbNodes, node.decorators) ||
|
||||
visitNodes(cbNode, cbNodes, node.modifiers) ||
|
||||
visitNode(cbNode, (<PropertyDeclaration>node).name) ||
|
||||
visitNode(cbNode, (<PropertyDeclaration>node).questionToken) ||
|
||||
visitNode(cbNode, (<PropertyDeclaration>node).exclamationToken) ||
|
||||
visitNode(cbNode, (<PropertyDeclaration>node).type) ||
|
||||
visitNode(cbNode, (<PropertyDeclaration>node).initializer);
|
||||
case SyntaxKind.PropertySignature:
|
||||
return visitNodes(cbNode, cbNodes, node.decorators) ||
|
||||
visitNodes(cbNode, cbNodes, node.modifiers) ||
|
||||
visitNode(cbNode, (<PropertySignature>node).name) ||
|
||||
visitNode(cbNode, (<PropertySignature>node).questionToken) ||
|
||||
visitNode(cbNode, (<PropertySignature>node).type) ||
|
||||
visitNode(cbNode, (<PropertySignature>node).initializer);
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
return visitNodes(cbNode, cbNodes, node.decorators) ||
|
||||
visitNodes(cbNode, cbNodes, node.modifiers) ||
|
||||
visitNode(cbNode, (<PropertyAssignment>node).name) ||
|
||||
visitNode(cbNode, (<PropertyAssignment>node).questionToken) ||
|
||||
visitNode(cbNode, (<PropertyAssignment>node).initializer);
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
return visitNodes(cbNode, cbNodes, node.decorators) ||
|
||||
visitNodes(cbNode, cbNodes, node.modifiers) ||
|
||||
visitNode(cbNode, (<VariableDeclaration>node).name) ||
|
||||
visitNode(cbNode, (<VariableDeclaration>node).exclamationToken) ||
|
||||
visitNode(cbNode, (<VariableDeclaration>node).type) ||
|
||||
visitNode(cbNode, (<VariableDeclaration>node).initializer);
|
||||
case SyntaxKind.BindingElement:
|
||||
return visitNodes(cbNode, cbNodes, node.decorators) ||
|
||||
visitNodes(cbNode, cbNodes, node.modifiers) ||
|
||||
visitNode(cbNode, (<VariableLikeDeclaration>node).propertyName) ||
|
||||
visitNode(cbNode, (<VariableLikeDeclaration>node).dotDotDotToken) ||
|
||||
visitNode(cbNode, (<VariableLikeDeclaration>node).name) ||
|
||||
visitNode(cbNode, (<VariableLikeDeclaration>node).questionToken) ||
|
||||
visitNode(cbNode, (<VariableLikeDeclaration>node).exclamationToken) ||
|
||||
visitNode(cbNode, (<VariableLikeDeclaration>node).type) ||
|
||||
visitNode(cbNode, (<VariableLikeDeclaration>node).initializer);
|
||||
visitNode(cbNode, (<BindingElement>node).propertyName) ||
|
||||
visitNode(cbNode, (<BindingElement>node).dotDotDotToken) ||
|
||||
visitNode(cbNode, (<BindingElement>node).name) ||
|
||||
visitNode(cbNode, (<BindingElement>node).initializer);
|
||||
case SyntaxKind.FunctionType:
|
||||
case SyntaxKind.ConstructorType:
|
||||
case SyntaxKind.CallSignature:
|
||||
@@ -5462,6 +5490,7 @@ namespace ts {
|
||||
switch (token()) {
|
||||
case SyntaxKind.OpenParenToken: // Method declaration
|
||||
case SyntaxKind.LessThanToken: // Generic Method declaration
|
||||
case SyntaxKind.ExclamationToken: // Non-null assertion on property name
|
||||
case SyntaxKind.ColonToken: // Type Annotation for declaration
|
||||
case SyntaxKind.EqualsToken: // Initializer for declaration
|
||||
case SyntaxKind.QuestionToken: // Not valid, but permitted so that it gets caught later on.
|
||||
|
||||
+37
-22
@@ -241,22 +241,28 @@ namespace ts {
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
const redForegroundEscapeSequence = "\u001b[91m";
|
||||
const yellowForegroundEscapeSequence = "\u001b[93m";
|
||||
const blueForegroundEscapeSequence = "\u001b[93m";
|
||||
/** @internal */
|
||||
export enum ForegroundColorEscapeSequences {
|
||||
Grey = "\u001b[90m",
|
||||
Red = "\u001b[91m",
|
||||
Yellow = "\u001b[93m",
|
||||
Blue = "\u001b[94m",
|
||||
Cyan = "\u001b[96m"
|
||||
}
|
||||
const gutterStyleSequence = "\u001b[30;47m";
|
||||
const gutterSeparator = " ";
|
||||
const resetEscapeSequence = "\u001b[0m";
|
||||
const ellipsis = "...";
|
||||
function getCategoryFormat(category: DiagnosticCategory): string {
|
||||
switch (category) {
|
||||
case DiagnosticCategory.Warning: return yellowForegroundEscapeSequence;
|
||||
case DiagnosticCategory.Error: return redForegroundEscapeSequence;
|
||||
case DiagnosticCategory.Message: return blueForegroundEscapeSequence;
|
||||
case DiagnosticCategory.Warning: return ForegroundColorEscapeSequences.Yellow;
|
||||
case DiagnosticCategory.Error: return ForegroundColorEscapeSequences.Red;
|
||||
case DiagnosticCategory.Message: return ForegroundColorEscapeSequences.Blue;
|
||||
}
|
||||
}
|
||||
|
||||
function formatAndReset(text: string, formatStyle: string) {
|
||||
/** @internal */
|
||||
export function formatColorAndReset(text: string, formatStyle: string) {
|
||||
return formatStyle + text + resetEscapeSequence;
|
||||
}
|
||||
|
||||
@@ -289,7 +295,7 @@ namespace ts {
|
||||
// If the error spans over 5 lines, we'll only show the first 2 and last 2 lines,
|
||||
// so we'll skip ahead to the second-to-last line.
|
||||
if (hasMoreThanFiveLines && firstLine + 1 < i && i < lastLine - 1) {
|
||||
context += formatAndReset(padLeft(ellipsis, gutterWidth), gutterStyleSequence) + gutterSeparator + host.getNewLine();
|
||||
context += formatColorAndReset(padLeft(ellipsis, gutterWidth), gutterStyleSequence) + gutterSeparator + host.getNewLine();
|
||||
i = lastLine - 1;
|
||||
}
|
||||
|
||||
@@ -300,12 +306,12 @@ namespace ts {
|
||||
lineContent = lineContent.replace("\t", " "); // convert tabs to single spaces
|
||||
|
||||
// Output the gutter and the actual contents of the line.
|
||||
context += formatAndReset(padLeft(i + 1 + "", gutterWidth), gutterStyleSequence) + gutterSeparator;
|
||||
context += formatColorAndReset(padLeft(i + 1 + "", gutterWidth), gutterStyleSequence) + gutterSeparator;
|
||||
context += lineContent + host.getNewLine();
|
||||
|
||||
// Output the gutter and the error span for the line using tildes.
|
||||
context += formatAndReset(padLeft("", gutterWidth), gutterStyleSequence) + gutterSeparator;
|
||||
context += redForegroundEscapeSequence;
|
||||
context += formatColorAndReset(padLeft("", gutterWidth), gutterStyleSequence) + gutterSeparator;
|
||||
context += ForegroundColorEscapeSequences.Red;
|
||||
if (i === firstLine) {
|
||||
// If we're on the last line, then limit it to the last character of the last line.
|
||||
// Otherwise, we'll just squiggle the rest of the line, giving 'slice' no end position.
|
||||
@@ -324,13 +330,19 @@ namespace ts {
|
||||
context += resetEscapeSequence;
|
||||
}
|
||||
|
||||
output += host.getNewLine();
|
||||
output += `${ relativeFileName }(${ firstLine + 1 },${ firstLineChar + 1 }): `;
|
||||
output += formatColorAndReset(relativeFileName, ForegroundColorEscapeSequences.Cyan);
|
||||
output += "(";
|
||||
output += formatColorAndReset(`${ firstLine + 1 }`, ForegroundColorEscapeSequences.Yellow);
|
||||
output += ",";
|
||||
output += formatColorAndReset(`${ firstLineChar + 1 }`, ForegroundColorEscapeSequences.Yellow);
|
||||
output += "): ";
|
||||
}
|
||||
|
||||
const categoryColor = getCategoryFormat(diagnostic.category);
|
||||
const category = DiagnosticCategory[diagnostic.category].toLowerCase();
|
||||
output += `${ formatAndReset(category, categoryColor) } TS${ diagnostic.code }: ${ flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine()) }`;
|
||||
output += formatColorAndReset(category, categoryColor);
|
||||
output += formatColorAndReset(` TS${ diagnostic.code }: `, ForegroundColorEscapeSequences.Grey);
|
||||
output += flattenDiagnosticMessageText(diagnostic.messageText, host.getNewLine());
|
||||
|
||||
if (diagnostic.file) {
|
||||
output += host.getNewLine();
|
||||
@@ -339,7 +351,7 @@ namespace ts {
|
||||
|
||||
output += host.getNewLine();
|
||||
}
|
||||
return output;
|
||||
return output + host.getNewLine();
|
||||
}
|
||||
|
||||
export function flattenDiagnosticMessageText(messageText: string | DiagnosticMessageChain, newLine: string): string {
|
||||
@@ -704,7 +716,7 @@ namespace ts {
|
||||
|
||||
interface OldProgramState {
|
||||
program: Program | undefined;
|
||||
file: SourceFile;
|
||||
oldSourceFile: SourceFile | undefined;
|
||||
/** The collection of paths modified *since* the old program. */
|
||||
modifiedFilePaths: Path[];
|
||||
}
|
||||
@@ -754,7 +766,6 @@ namespace ts {
|
||||
/** A transient placeholder used to mark predicted resolution in the result list. */
|
||||
const predictedToResolveToAmbientModuleMarker: ResolvedModuleFull = <any>{};
|
||||
|
||||
|
||||
for (let i = 0; i < moduleNames.length; i++) {
|
||||
const moduleName = moduleNames[i];
|
||||
// If the source file is unchanged and doesnt have invalidated resolution, reuse the module resolutions
|
||||
@@ -825,9 +836,13 @@ namespace ts {
|
||||
// If we change our policy of rechecking failed lookups on each program create,
|
||||
// we should adjust the value returned here.
|
||||
function moduleNameResolvesToAmbientModuleInNonModifiedFile(moduleName: string, oldProgramState: OldProgramState): boolean {
|
||||
const resolutionToFile = getResolvedModule(oldProgramState.file, moduleName);
|
||||
if (resolutionToFile) {
|
||||
// module used to be resolved to file - ignore it
|
||||
const resolutionToFile = getResolvedModule(oldProgramState.oldSourceFile, moduleName);
|
||||
const resolvedFile = resolutionToFile && oldProgramState.program && oldProgramState.program.getSourceFile(resolutionToFile.resolvedFileName);
|
||||
if (resolutionToFile && resolvedFile && !resolvedFile.externalModuleIndicator) {
|
||||
// In the old program, we resolved to an ambient module that was in the same
|
||||
// place as we expected to find an actual module file.
|
||||
// We actually need to return 'false' here even though this seems like a 'true' case
|
||||
// because the normal module resolution algorithm will find this anyway.
|
||||
return false;
|
||||
}
|
||||
const ambientModule = oldProgramState.program && oldProgramState.program.getTypeChecker().tryFindAmbientModuleWithoutAugmentations(moduleName);
|
||||
@@ -1001,7 +1016,7 @@ namespace ts {
|
||||
const newSourceFilePath = getNormalizedAbsolutePath(newSourceFile.fileName, currentDirectory);
|
||||
if (resolveModuleNamesWorker) {
|
||||
const moduleNames = getModuleNames(newSourceFile);
|
||||
const oldProgramState = { program: oldProgram, file: oldSourceFile, modifiedFilePaths };
|
||||
const oldProgramState: OldProgramState = { program: oldProgram, oldSourceFile, modifiedFilePaths };
|
||||
const resolutions = resolveModuleNamesReusingOldState(moduleNames, newSourceFilePath, newSourceFile, oldProgramState);
|
||||
// ensure that module resolution results are still correct
|
||||
const resolutionsChanged = hasChangesInResolutions(moduleNames, resolutions, oldSourceFile.resolvedModules, moduleResolutionIsEqualTo);
|
||||
@@ -1945,7 +1960,7 @@ namespace ts {
|
||||
if (file.imports.length || file.moduleAugmentations.length) {
|
||||
// Because global augmentation doesn't have string literal name, we can check for global augmentation as such.
|
||||
const moduleNames = getModuleNames(file);
|
||||
const oldProgramState = { program: oldProgram, file, modifiedFilePaths };
|
||||
const oldProgramState: OldProgramState = { program: oldProgram, oldSourceFile: oldProgram && oldProgram.getSourceFile(file.fileName), modifiedFilePaths };
|
||||
const resolutions = resolveModuleNamesReusingOldState(moduleNames, getNormalizedAbsolutePath(file.fileName, currentDirectory), file, oldProgramState);
|
||||
Debug.assert(resolutions.length === moduleNames.length);
|
||||
for (let i = 0; i < moduleNames.length; i++) {
|
||||
|
||||
+126
-21
@@ -561,9 +561,9 @@ namespace ts {
|
||||
return false;
|
||||
}
|
||||
|
||||
function scanConflictMarkerTrivia(text: string, pos: number, error?: ErrorCallback) {
|
||||
function scanConflictMarkerTrivia(text: string, pos: number, error?: (diag: DiagnosticMessage, pos?: number, len?: number) => void) {
|
||||
if (error) {
|
||||
error(Diagnostics.Merge_conflict_marker_encountered, mergeConflictMarkerLength);
|
||||
error(Diagnostics.Merge_conflict_marker_encountered, pos, mergeConflictMarkerLength);
|
||||
}
|
||||
|
||||
const ch = text.charCodeAt(pos);
|
||||
@@ -852,34 +852,92 @@ namespace ts {
|
||||
scanRange,
|
||||
};
|
||||
|
||||
function error(message: DiagnosticMessage, length?: number): void {
|
||||
function error(message: DiagnosticMessage): void;
|
||||
function error(message: DiagnosticMessage, errPos: number, length: number): void;
|
||||
function error(message: DiagnosticMessage, errPos: number = pos, length?: number): void {
|
||||
if (onError) {
|
||||
const oldPos = pos;
|
||||
pos = errPos;
|
||||
onError(message, length || 0);
|
||||
pos = oldPos;
|
||||
}
|
||||
}
|
||||
|
||||
function scanNumberFragment(): string {
|
||||
let start = pos;
|
||||
let allowSeparator = false;
|
||||
let isPreviousTokenSeparator = false;
|
||||
let result = "";
|
||||
while (true) {
|
||||
const ch = text.charCodeAt(pos);
|
||||
if (ch === CharacterCodes._) {
|
||||
tokenFlags |= TokenFlags.ContainsSeparator;
|
||||
if (allowSeparator) {
|
||||
allowSeparator = false;
|
||||
isPreviousTokenSeparator = true;
|
||||
result += text.substring(start, pos);
|
||||
}
|
||||
else if (isPreviousTokenSeparator) {
|
||||
error(Diagnostics.Multiple_consecutive_numeric_separators_are_not_permitted, pos, 1);
|
||||
}
|
||||
else {
|
||||
error(Diagnostics.Numeric_separators_are_not_allowed_here, pos, 1);
|
||||
}
|
||||
pos++;
|
||||
start = pos;
|
||||
continue;
|
||||
}
|
||||
if (isDigit(ch)) {
|
||||
allowSeparator = true;
|
||||
isPreviousTokenSeparator = false;
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (text.charCodeAt(pos - 1) === CharacterCodes._) {
|
||||
error(Diagnostics.Numeric_separators_are_not_allowed_here, pos - 1, 1);
|
||||
}
|
||||
return result + text.substring(start, pos);
|
||||
}
|
||||
|
||||
function scanNumber(): string {
|
||||
const start = pos;
|
||||
while (isDigit(text.charCodeAt(pos))) pos++;
|
||||
const mainFragment = scanNumberFragment();
|
||||
let decimalFragment: string;
|
||||
let scientificFragment: string;
|
||||
if (text.charCodeAt(pos) === CharacterCodes.dot) {
|
||||
pos++;
|
||||
while (isDigit(text.charCodeAt(pos))) pos++;
|
||||
decimalFragment = scanNumberFragment();
|
||||
}
|
||||
let end = pos;
|
||||
if (text.charCodeAt(pos) === CharacterCodes.E || text.charCodeAt(pos) === CharacterCodes.e) {
|
||||
pos++;
|
||||
tokenFlags |= TokenFlags.Scientific;
|
||||
if (text.charCodeAt(pos) === CharacterCodes.plus || text.charCodeAt(pos) === CharacterCodes.minus) pos++;
|
||||
if (isDigit(text.charCodeAt(pos))) {
|
||||
pos++;
|
||||
while (isDigit(text.charCodeAt(pos))) pos++;
|
||||
end = pos;
|
||||
}
|
||||
else {
|
||||
const preNumericPart = pos;
|
||||
const finalFragment = scanNumberFragment();
|
||||
if (!finalFragment) {
|
||||
error(Diagnostics.Digit_expected);
|
||||
}
|
||||
else {
|
||||
scientificFragment = text.substring(end, preNumericPart) + finalFragment;
|
||||
end = pos;
|
||||
}
|
||||
}
|
||||
if (tokenFlags & TokenFlags.ContainsSeparator) {
|
||||
let result = mainFragment;
|
||||
if (decimalFragment) {
|
||||
result += "." + decimalFragment;
|
||||
}
|
||||
if (scientificFragment) {
|
||||
result += scientificFragment;
|
||||
}
|
||||
return "" + +result;
|
||||
}
|
||||
else {
|
||||
return "" + +(text.substring(start, end)); // No need to use all the fragments; no _ removal needed
|
||||
}
|
||||
return "" + +(text.substring(start, end));
|
||||
}
|
||||
|
||||
function scanOctalDigits(): number {
|
||||
@@ -894,23 +952,41 @@ namespace ts {
|
||||
* Scans the given number of hexadecimal digits in the text,
|
||||
* returning -1 if the given number is unavailable.
|
||||
*/
|
||||
function scanExactNumberOfHexDigits(count: number): number {
|
||||
return scanHexDigits(/*minCount*/ count, /*scanAsManyAsPossible*/ false);
|
||||
function scanExactNumberOfHexDigits(count: number, canHaveSeparators: boolean): number {
|
||||
return scanHexDigits(/*minCount*/ count, /*scanAsManyAsPossible*/ false, canHaveSeparators);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans as many hexadecimal digits as are available in the text,
|
||||
* returning -1 if the given number of digits was unavailable.
|
||||
*/
|
||||
function scanMinimumNumberOfHexDigits(count: number): number {
|
||||
return scanHexDigits(/*minCount*/ count, /*scanAsManyAsPossible*/ true);
|
||||
function scanMinimumNumberOfHexDigits(count: number, canHaveSeparators: boolean): number {
|
||||
return scanHexDigits(/*minCount*/ count, /*scanAsManyAsPossible*/ true, canHaveSeparators);
|
||||
}
|
||||
|
||||
function scanHexDigits(minCount: number, scanAsManyAsPossible: boolean): number {
|
||||
function scanHexDigits(minCount: number, scanAsManyAsPossible: boolean, canHaveSeparators: boolean): number {
|
||||
let digits = 0;
|
||||
let value = 0;
|
||||
let allowSeparator = false;
|
||||
let isPreviousTokenSeparator = false;
|
||||
while (digits < minCount || scanAsManyAsPossible) {
|
||||
const ch = text.charCodeAt(pos);
|
||||
if (canHaveSeparators && ch === CharacterCodes._) {
|
||||
tokenFlags |= TokenFlags.ContainsSeparator;
|
||||
if (allowSeparator) {
|
||||
allowSeparator = false;
|
||||
isPreviousTokenSeparator = true;
|
||||
}
|
||||
else if (isPreviousTokenSeparator) {
|
||||
error(Diagnostics.Multiple_consecutive_numeric_separators_are_not_permitted, pos, 1);
|
||||
}
|
||||
else {
|
||||
error(Diagnostics.Numeric_separators_are_not_allowed_here, pos, 1);
|
||||
}
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
allowSeparator = canHaveSeparators;
|
||||
if (ch >= CharacterCodes._0 && ch <= CharacterCodes._9) {
|
||||
value = value * 16 + ch - CharacterCodes._0;
|
||||
}
|
||||
@@ -925,10 +1001,14 @@ namespace ts {
|
||||
}
|
||||
pos++;
|
||||
digits++;
|
||||
isPreviousTokenSeparator = false;
|
||||
}
|
||||
if (digits < minCount) {
|
||||
value = -1;
|
||||
}
|
||||
if (text.charCodeAt(pos - 1) === CharacterCodes._) {
|
||||
error(Diagnostics.Numeric_separators_are_not_allowed_here, pos - 1, 1);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -1097,7 +1177,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function scanHexadecimalEscape(numDigits: number): string {
|
||||
const escapedValue = scanExactNumberOfHexDigits(numDigits);
|
||||
const escapedValue = scanExactNumberOfHexDigits(numDigits, /*canHaveSeparators*/ false);
|
||||
|
||||
if (escapedValue >= 0) {
|
||||
return String.fromCharCode(escapedValue);
|
||||
@@ -1109,7 +1189,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
function scanExtendedUnicodeEscape(): string {
|
||||
const escapedValue = scanMinimumNumberOfHexDigits(1);
|
||||
const escapedValue = scanMinimumNumberOfHexDigits(1, /*canHaveSeparators*/ false);
|
||||
let isInvalidExtendedEscape = false;
|
||||
|
||||
// Validate the value of the digit
|
||||
@@ -1162,7 +1242,7 @@ namespace ts {
|
||||
if (pos + 5 < end && text.charCodeAt(pos + 1) === CharacterCodes.u) {
|
||||
const start = pos;
|
||||
pos += 2;
|
||||
const value = scanExactNumberOfHexDigits(4);
|
||||
const value = scanExactNumberOfHexDigits(4, /*canHaveSeparators*/ false);
|
||||
pos = start;
|
||||
return value;
|
||||
}
|
||||
@@ -1218,8 +1298,27 @@ namespace ts {
|
||||
// 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 separatorAllowed = false;
|
||||
let isPreviousTokenSeparator = false;
|
||||
while (true) {
|
||||
const ch = text.charCodeAt(pos);
|
||||
// Numeric seperators are allowed anywhere within a numeric literal, except not at the beginning, or following another separator
|
||||
if (ch === CharacterCodes._) {
|
||||
tokenFlags |= TokenFlags.ContainsSeparator;
|
||||
if (separatorAllowed) {
|
||||
separatorAllowed = false;
|
||||
isPreviousTokenSeparator = true;
|
||||
}
|
||||
else if (isPreviousTokenSeparator) {
|
||||
error(Diagnostics.Multiple_consecutive_numeric_separators_are_not_permitted, pos, 1);
|
||||
}
|
||||
else {
|
||||
error(Diagnostics.Numeric_separators_are_not_allowed_here, pos, 1);
|
||||
}
|
||||
pos++;
|
||||
continue;
|
||||
}
|
||||
separatorAllowed = true;
|
||||
const valueOfCh = ch - CharacterCodes._0;
|
||||
if (!isDigit(ch) || valueOfCh >= base) {
|
||||
break;
|
||||
@@ -1227,11 +1326,17 @@ namespace ts {
|
||||
value = value * base + valueOfCh;
|
||||
pos++;
|
||||
numberOfDigits++;
|
||||
isPreviousTokenSeparator = false;
|
||||
}
|
||||
// Invalid binaryIntegerLiteral or octalIntegerLiteral
|
||||
if (numberOfDigits === 0) {
|
||||
return -1;
|
||||
}
|
||||
if (text.charCodeAt(pos - 1) === CharacterCodes._) {
|
||||
// Literal ends with underscore - not allowed
|
||||
error(Diagnostics.Numeric_separators_are_not_allowed_here, pos - 1, 1);
|
||||
return value;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
@@ -1435,7 +1540,7 @@ namespace ts {
|
||||
case CharacterCodes._0:
|
||||
if (pos + 2 < end && (text.charCodeAt(pos + 1) === CharacterCodes.X || text.charCodeAt(pos + 1) === CharacterCodes.x)) {
|
||||
pos += 2;
|
||||
let value = scanMinimumNumberOfHexDigits(1);
|
||||
let value = scanMinimumNumberOfHexDigits(1, /*canHaveSeparators*/ true);
|
||||
if (value < 0) {
|
||||
error(Diagnostics.Hexadecimal_digit_expected);
|
||||
value = 0;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
namespace ts {
|
||||
export function createGetSymbolWalker(
|
||||
getRestTypeOfSignature: (sig: Signature) => Type,
|
||||
getTypePredicateOfSignature: (sig: Signature) => TypePredicate | undefined,
|
||||
getReturnTypeOfSignature: (sig: Signature) => Type,
|
||||
getBaseTypes: (type: Type) => Type[],
|
||||
resolveStructuredTypeMembers: (type: ObjectType) => ResolvedType,
|
||||
@@ -117,8 +118,9 @@ namespace ts {
|
||||
}
|
||||
|
||||
function visitSignature(signature: Signature): void {
|
||||
if (signature.typePredicate) {
|
||||
visitType(signature.typePredicate.type);
|
||||
const typePredicate = getTypePredicateOfSignature(signature);
|
||||
if (typePredicate) {
|
||||
visitType(typePredicate.type);
|
||||
}
|
||||
forEach(signature.typeParameters, visitType);
|
||||
|
||||
|
||||
@@ -72,6 +72,7 @@ namespace ts {
|
||||
/*@internal*/ debugMode?: boolean;
|
||||
setTimeout?(callback: (...args: any[]) => void, ms: number, ...args: any[]): any;
|
||||
clearTimeout?(timeoutId: any): void;
|
||||
clearScreen?(): void;
|
||||
}
|
||||
|
||||
export interface FileWatcher {
|
||||
@@ -436,6 +437,9 @@ namespace ts {
|
||||
}
|
||||
|
||||
const nodeSystem: System = {
|
||||
clearScreen: () => {
|
||||
process.stdout.write("\x1Bc");
|
||||
},
|
||||
args: process.argv.slice(2),
|
||||
newLine: _os.EOL,
|
||||
useCaseSensitiveFileNames,
|
||||
|
||||
@@ -2553,7 +2553,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
/**
|
||||
* Visits an ObjectLiteralExpression with computed propety names.
|
||||
* Visits an ObjectLiteralExpression with computed property names.
|
||||
*
|
||||
* @param node An ObjectLiteralExpression node.
|
||||
*/
|
||||
|
||||
+92
-33
@@ -584,6 +584,40 @@ namespace ts {
|
||||
| JSDocFunctionType
|
||||
| EndOfFileToken;
|
||||
|
||||
export type HasType =
|
||||
| SignatureDeclaration
|
||||
| VariableDeclaration
|
||||
| ParameterDeclaration
|
||||
| PropertySignature
|
||||
| PropertyDeclaration
|
||||
| TypePredicateNode
|
||||
| ParenthesizedTypeNode
|
||||
| TypeOperatorNode
|
||||
| MappedTypeNode
|
||||
| AssertionExpression
|
||||
| TypeAliasDeclaration
|
||||
| JSDocTypeExpression
|
||||
| JSDocNonNullableType
|
||||
| JSDocNullableType
|
||||
| JSDocOptionalType
|
||||
| JSDocVariadicType;
|
||||
|
||||
export type HasInitializer =
|
||||
| HasExpressionInitializer
|
||||
| ForStatement
|
||||
| ForInStatement
|
||||
| ForOfStatement
|
||||
| JsxAttribute;
|
||||
|
||||
export type HasExpressionInitializer =
|
||||
| VariableDeclaration
|
||||
| ParameterDeclaration
|
||||
| BindingElement
|
||||
| PropertySignature
|
||||
| PropertyDeclaration
|
||||
| PropertyAssignment
|
||||
| EnumMember;
|
||||
|
||||
/* @internal */
|
||||
export type MutableNodeArray<T extends Node> = NodeArray<T> & T[];
|
||||
|
||||
@@ -793,6 +827,9 @@ namespace ts {
|
||||
initializer?: Expression; // Optional initializer
|
||||
}
|
||||
|
||||
/*@internal*/
|
||||
export type BindingElementGrandparent = BindingElement["parent"]["parent"];
|
||||
|
||||
export interface PropertySignature extends TypeElement, JSDocContainer {
|
||||
kind: SyntaxKind.PropertySignature;
|
||||
name: PropertyName; // Declared property name
|
||||
@@ -848,25 +885,18 @@ namespace ts {
|
||||
expression: Expression;
|
||||
}
|
||||
|
||||
// SyntaxKind.VariableDeclaration
|
||||
// SyntaxKind.Parameter
|
||||
// SyntaxKind.BindingElement
|
||||
// SyntaxKind.Property
|
||||
// SyntaxKind.PropertyAssignment
|
||||
// SyntaxKind.JsxAttribute
|
||||
// SyntaxKind.ShorthandPropertyAssignment
|
||||
// SyntaxKind.EnumMember
|
||||
// SyntaxKind.JSDocPropertyTag
|
||||
// SyntaxKind.JSDocParameterTag
|
||||
export interface VariableLikeDeclaration extends NamedDeclaration {
|
||||
propertyName?: PropertyName;
|
||||
dotDotDotToken?: DotDotDotToken;
|
||||
name: DeclarationName;
|
||||
questionToken?: QuestionToken;
|
||||
exclamationToken?: ExclamationToken;
|
||||
type?: TypeNode;
|
||||
initializer?: Expression;
|
||||
}
|
||||
export type VariableLikeDeclaration =
|
||||
| VariableDeclaration
|
||||
| ParameterDeclaration
|
||||
| BindingElement
|
||||
| PropertyDeclaration
|
||||
| PropertyAssignment
|
||||
| PropertySignature
|
||||
| JsxAttribute
|
||||
| ShorthandPropertyAssignment
|
||||
| EnumMember
|
||||
| JSDocPropertyTag
|
||||
| JSDocParameterTag;
|
||||
|
||||
export interface PropertyLikeDeclaration extends NamedDeclaration {
|
||||
name: PropertyName;
|
||||
@@ -949,7 +979,7 @@ namespace ts {
|
||||
|
||||
export interface ConstructorDeclaration extends FunctionLikeDeclarationBase, ClassElement, JSDocContainer {
|
||||
kind: SyntaxKind.Constructor;
|
||||
parent?: ClassDeclaration | ClassExpression;
|
||||
parent?: ClassLikeDeclaration;
|
||||
body?: FunctionBody;
|
||||
/* @internal */ returnFlowNode?: FlowNode;
|
||||
}
|
||||
@@ -957,14 +987,14 @@ namespace ts {
|
||||
/** For when we encounter a semicolon in a class declaration. ES6 allows these as class elements. */
|
||||
export interface SemicolonClassElement extends ClassElement {
|
||||
kind: SyntaxKind.SemicolonClassElement;
|
||||
parent?: ClassDeclaration | ClassExpression;
|
||||
parent?: ClassLikeDeclaration;
|
||||
}
|
||||
|
||||
// See the comment on MethodDeclaration for the intuition behind GetAccessorDeclaration being a
|
||||
// ClassElement and an ObjectLiteralElement.
|
||||
export interface GetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer {
|
||||
kind: SyntaxKind.GetAccessor;
|
||||
parent?: ClassDeclaration | ClassExpression | ObjectLiteralExpression;
|
||||
parent?: ClassLikeDeclaration | ObjectLiteralExpression;
|
||||
name: PropertyName;
|
||||
body?: FunctionBody;
|
||||
}
|
||||
@@ -973,7 +1003,7 @@ namespace ts {
|
||||
// ClassElement and an ObjectLiteralElement.
|
||||
export interface SetAccessorDeclaration extends FunctionLikeDeclarationBase, ClassElement, ObjectLiteralElement, JSDocContainer {
|
||||
kind: SyntaxKind.SetAccessor;
|
||||
parent?: ClassDeclaration | ClassExpression | ObjectLiteralExpression;
|
||||
parent?: ClassLikeDeclaration | ObjectLiteralExpression;
|
||||
name: PropertyName;
|
||||
body?: FunctionBody;
|
||||
}
|
||||
@@ -982,7 +1012,7 @@ namespace ts {
|
||||
|
||||
export interface IndexSignatureDeclaration extends SignatureDeclarationBase, ClassElement, TypeElement {
|
||||
kind: SyntaxKind.IndexSignature;
|
||||
parent?: ClassDeclaration | ClassExpression | InterfaceDeclaration | TypeLiteralNode;
|
||||
parent?: ClassLikeDeclaration | InterfaceDeclaration | TypeLiteralNode;
|
||||
}
|
||||
|
||||
export interface TypeNode extends Node {
|
||||
@@ -1490,8 +1520,9 @@ namespace ts {
|
||||
HexSpecifier = 1 << 6, // e.g. `0x00000000`
|
||||
BinarySpecifier = 1 << 7, // e.g. `0b0110010000000000`
|
||||
OctalSpecifier = 1 << 8, // e.g. `0o777`
|
||||
ContainsSeparator = 1 << 9, // e.g. `0b1100_0101`
|
||||
BinaryOrOctalSpecifier = BinarySpecifier | OctalSpecifier,
|
||||
NumericLiteralFlags = Scientific | Octal | HexSpecifier | BinarySpecifier | OctalSpecifier
|
||||
NumericLiteralFlags = Scientific | Octal | HexSpecifier | BinarySpecifier | OctalSpecifier | ContainsSeparator
|
||||
}
|
||||
|
||||
export interface NumericLiteral extends LiteralExpression {
|
||||
@@ -1986,7 +2017,7 @@ namespace ts {
|
||||
|
||||
export interface HeritageClause extends Node {
|
||||
kind: SyntaxKind.HeritageClause;
|
||||
parent?: InterfaceDeclaration | ClassDeclaration | ClassExpression;
|
||||
parent?: InterfaceDeclaration | ClassLikeDeclaration;
|
||||
token: SyntaxKind.ExtendsKeyword | SyntaxKind.ImplementsKeyword;
|
||||
types: NodeArray<ExpressionWithTypeArguments>;
|
||||
}
|
||||
@@ -2478,7 +2509,7 @@ namespace ts {
|
||||
// Stores a mapping 'external module reference text' -> 'resolved file name' | undefined
|
||||
// It is used to resolve module names in the checker.
|
||||
// Content of this field should never be used directly - use getResolvedModuleFileName/setResolvedModuleFileName functions instead
|
||||
/* @internal */ resolvedModules: Map<ResolvedModuleFull>;
|
||||
/* @internal */ resolvedModules: Map<ResolvedModuleFull | undefined>;
|
||||
/* @internal */ resolvedTypeReferenceDirectiveNames: Map<ResolvedTypeReferenceDirective>;
|
||||
/* @internal */ imports: ReadonlyArray<StringLiteral>;
|
||||
// Identifier only if `declare global`
|
||||
@@ -2738,6 +2769,8 @@ namespace ts {
|
||||
getAugmentedPropertiesOfType(type: Type): Symbol[];
|
||||
getRootSymbols(symbol: Symbol): Symbol[];
|
||||
getContextualType(node: Expression): Type | undefined;
|
||||
/* @internal */ isContextSensitive(node: Expression | MethodDeclaration | ObjectLiteralElementLike | JsxAttributeLike): boolean;
|
||||
|
||||
/**
|
||||
* returns unknownSignature in the case of an error.
|
||||
* @param argumentCount Apparent number of arguments, passed in case of a possibly incomplete call. This should come from an ArgumentListInfo. See `signatureHelp.ts`.
|
||||
@@ -2752,6 +2785,8 @@ namespace ts {
|
||||
|
||||
getConstantValue(node: EnumMember | PropertyAccessExpression | ElementAccessExpression): string | number | undefined;
|
||||
isValidPropertyAccess(node: PropertyAccessExpression | QualifiedName, propertyName: string): boolean;
|
||||
/** Exclude accesses to private properties or methods with a `this` parameter that `type` doesn't satisfy. */
|
||||
/* @internal */ isValidPropertyAccessForCompletions(node: PropertyAccessExpression, type: Type, property: Symbol): boolean;
|
||||
/** Follow all aliases to get the original symbol. */
|
||||
getAliasedSymbol(symbol: Symbol): Symbol;
|
||||
/** Follow a *single* alias to get the immediately aliased symbol. */
|
||||
@@ -2786,12 +2821,22 @@ namespace ts {
|
||||
/* @internal */ getNullType(): Type;
|
||||
/* @internal */ getESSymbolType(): Type;
|
||||
/* @internal */ getNeverType(): Type;
|
||||
/* @internal */ getUnionType(types: Type[], subtypeReduction?: boolean): Type;
|
||||
/* @internal */ getUnionType(types: Type[], subtypeReduction?: UnionReduction): Type;
|
||||
/* @internal */ createArrayType(elementType: Type): Type;
|
||||
/* @internal */ createPromiseType(type: Type): Type;
|
||||
|
||||
/* @internal */ createAnonymousType(symbol: Symbol, members: SymbolTable, callSignatures: Signature[], constructSignatures: Signature[], stringIndexInfo: IndexInfo, numberIndexInfo: IndexInfo): Type;
|
||||
/* @internal */ createSignature(declaration: SignatureDeclaration, typeParameters: TypeParameter[], thisParameter: Symbol | undefined, parameters: Symbol[], resolvedReturnType: Type, typePredicate: TypePredicate, minArgumentCount: number, hasRestParameter: boolean, hasLiteralTypes: boolean): Signature;
|
||||
/* @internal */ createSignature(
|
||||
declaration: SignatureDeclaration,
|
||||
typeParameters: TypeParameter[],
|
||||
thisParameter: Symbol | undefined,
|
||||
parameters: Symbol[],
|
||||
resolvedReturnType: Type,
|
||||
typePredicate: TypePredicate | undefined,
|
||||
minArgumentCount: number,
|
||||
hasRestParameter: boolean,
|
||||
hasLiteralTypes: boolean,
|
||||
): Signature;
|
||||
/* @internal */ createSymbol(flags: SymbolFlags, name: __String): TransientSymbol;
|
||||
/* @internal */ createIndexInfo(type: Type, isReadonly: boolean, declaration?: SignatureDeclaration): IndexInfo;
|
||||
/* @internal */ isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags, shouldComputeAliasToMarkVisible: boolean): SymbolAccessibilityResult;
|
||||
@@ -2831,6 +2876,13 @@ namespace ts {
|
||||
/* @internal */ getAccessibleSymbolChain(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, useOnlyExternalAliasing: boolean): Symbol[] | undefined;
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export const enum UnionReduction {
|
||||
None = 0,
|
||||
Literal,
|
||||
Subtype
|
||||
}
|
||||
|
||||
export enum NodeBuilderFlags {
|
||||
None = 0,
|
||||
// Options
|
||||
@@ -3638,7 +3690,13 @@ namespace ts {
|
||||
/* @internal */
|
||||
thisParameter?: Symbol; // symbol of this-type parameter
|
||||
/* @internal */
|
||||
resolvedReturnType: Type; // Resolved return type
|
||||
// See comment in `instantiateSignature` for why these are set lazily.
|
||||
resolvedReturnType: Type | undefined; // Lazily set by `getReturnTypeOfSignature`.
|
||||
/* @internal */
|
||||
// Lazily set by `getTypePredicateOfSignature`.
|
||||
// `undefined` indicates a type predicate that has not yet been computed.
|
||||
// Uses a special `noTypePredicate` sentinel value to indicate that there is no type predicate. This looks like a TypePredicate at runtime to avoid polymorphism.
|
||||
resolvedTypePredicate: TypePredicate | undefined;
|
||||
/* @internal */
|
||||
minArgumentCount: number; // Number of non-optional parameters
|
||||
/* @internal */
|
||||
@@ -3658,8 +3716,6 @@ namespace ts {
|
||||
/* @internal */
|
||||
isolatedSignatureType?: ObjectType; // A manufactured type that just contains the signature for purposes of signature comparison
|
||||
/* @internal */
|
||||
typePredicate?: TypePredicate;
|
||||
/* @internal */
|
||||
instantiations?: Map<Signature>; // Generic signature instantiation cache
|
||||
}
|
||||
|
||||
@@ -3961,7 +4017,8 @@ namespace ts {
|
||||
ES2015 = 2,
|
||||
ES2016 = 3,
|
||||
ES2017 = 4,
|
||||
ESNext = 5,
|
||||
ES2018 = 5,
|
||||
ESNext = 6,
|
||||
Latest = ESNext,
|
||||
}
|
||||
|
||||
@@ -4228,6 +4285,8 @@ namespace ts {
|
||||
* If changing this, remember to change `moduleResolutionIsEqualTo`.
|
||||
*/
|
||||
export interface ResolvedModuleFull extends ResolvedModule {
|
||||
/* @internal */
|
||||
readonly originalPath?: string;
|
||||
/**
|
||||
* Extension of resolvedFileName. This must match what's at the end of resolvedFileName.
|
||||
* This is optional for backwards-compatibility, but will be added if not provided.
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
/* @internal */
|
||||
namespace ts {
|
||||
export const emptyArray: never[] = [] as never[];
|
||||
export const resolvingEmptyArray: never[] = [] as never[];
|
||||
export const emptyMap: ReadonlyMap<never> = createMap<never>();
|
||||
|
||||
export const externalHelpersModuleNameText = "tslib";
|
||||
@@ -101,6 +102,7 @@ namespace ts {
|
||||
return oldResolution.isExternalLibraryImport === newResolution.isExternalLibraryImport &&
|
||||
oldResolution.extension === newResolution.extension &&
|
||||
oldResolution.resolvedFileName === newResolution.resolvedFileName &&
|
||||
oldResolution.originalPath === newResolution.originalPath &&
|
||||
packageIdIsEqual(oldResolution.packageId, newResolution.packageId);
|
||||
}
|
||||
|
||||
@@ -345,7 +347,7 @@ namespace ts {
|
||||
export function getLiteralText(node: LiteralLikeNode, sourceFile: SourceFile) {
|
||||
// If we don't need to downlevel and we can reach the original source text using
|
||||
// the node's parent reference, then simply get the text as it was originally written.
|
||||
if (!nodeIsSynthesized(node) && node.parent) {
|
||||
if (!nodeIsSynthesized(node) && node.parent && !(isNumericLiteral(node) && node.numericLiteralFlags & TokenFlags.ContainsSeparator)) {
|
||||
return getSourceTextOfNodeFromSourceFile(sourceFile, node);
|
||||
}
|
||||
|
||||
@@ -547,7 +549,7 @@ namespace ts {
|
||||
// Return display name of an identifier
|
||||
// Computed property names will just be emitted as "[<expr>]", where <expr> is the source
|
||||
// text of the expression in the computed property.
|
||||
export function declarationNameToString(name: DeclarationName) {
|
||||
export function declarationNameToString(name: DeclarationName | QualifiedName) {
|
||||
return getFullWidth(name) === 0 ? "(Missing)" : getTextOfNode(name);
|
||||
}
|
||||
|
||||
@@ -783,7 +785,7 @@ namespace ts {
|
||||
case SyntaxKind.PropertySignature:
|
||||
case SyntaxKind.Parameter:
|
||||
case SyntaxKind.VariableDeclaration:
|
||||
return node === (<VariableLikeDeclaration>parent).type;
|
||||
return node === (parent as HasType).type;
|
||||
case SyntaxKind.FunctionDeclaration:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
@@ -1339,7 +1341,7 @@ namespace ts {
|
||||
case SyntaxKind.EnumMember:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
case SyntaxKind.BindingElement:
|
||||
return (<VariableLikeDeclaration>parent).initializer === node;
|
||||
return (parent as HasInitializer).initializer === node;
|
||||
case SyntaxKind.ExpressionStatement:
|
||||
case SyntaxKind.IfStatement:
|
||||
case SyntaxKind.DoStatement:
|
||||
@@ -1649,7 +1651,7 @@ namespace ts {
|
||||
result = addRange(result, getJSDocParameterTags(node as ParameterDeclaration));
|
||||
}
|
||||
|
||||
if (isVariableLike(node) && node.initializer && hasJSDocNodes(node.initializer)) {
|
||||
if (isVariableLike(node) && hasInitializer(node) && hasJSDocNodes(node.initializer)) {
|
||||
result = addRange(result, node.initializer.jsDoc);
|
||||
}
|
||||
|
||||
@@ -2815,8 +2817,8 @@ namespace ts {
|
||||
* Gets the effective type annotation of a variable, parameter, or property. If the node was
|
||||
* parsed in a JavaScript file, gets the type annotation from JSDoc.
|
||||
*/
|
||||
export function getEffectiveTypeAnnotationNode(node: VariableLikeDeclaration, checkJSDoc?: boolean): TypeNode | undefined {
|
||||
if (node.type) {
|
||||
export function getEffectiveTypeAnnotationNode(node: Node, checkJSDoc?: boolean): TypeNode | undefined {
|
||||
if (hasType(node)) {
|
||||
return node.type;
|
||||
}
|
||||
if (checkJSDoc || isInJavaScriptFile(node)) {
|
||||
@@ -3696,6 +3698,10 @@ namespace ts {
|
||||
export function typeHasCallOrConstructSignatures(type: Type, checker: TypeChecker) {
|
||||
return checker.getSignaturesOfType(type, SignatureKind.Call).length !== 0 || checker.getSignaturesOfType(type, SignatureKind.Construct).length !== 0;
|
||||
}
|
||||
|
||||
export function forSomeAncestorDirectory(directory: string, callback: (directory: string) => boolean): boolean {
|
||||
return !!forEachAncestorDirectory(directory, d => callback(d) ? true : undefined);
|
||||
}
|
||||
}
|
||||
|
||||
namespace ts {
|
||||
@@ -5228,6 +5234,18 @@ namespace ts {
|
||||
return node && (node.kind === SyntaxKind.GetAccessor || node.kind === SyntaxKind.SetAccessor);
|
||||
}
|
||||
|
||||
/* @internal */
|
||||
export function isMethodOrAccessor(node: Node): node is MethodDeclaration | AccessorDeclaration {
|
||||
switch (node.kind) {
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Type members
|
||||
|
||||
export function isTypeElement(node: Node): node is TypeElement {
|
||||
@@ -5807,4 +5825,22 @@ namespace ts {
|
||||
export function hasJSDocNodes(node: Node): node is HasJSDoc {
|
||||
return !!(node as JSDocContainer).jsDoc && (node as JSDocContainer).jsDoc.length > 0;
|
||||
}
|
||||
|
||||
/** True if has type node attached to it. */
|
||||
/* @internal */
|
||||
export function hasType(node: Node): node is HasType {
|
||||
return !!(node as HasType).type;
|
||||
}
|
||||
|
||||
/** True if has initializer node attached to it. */
|
||||
/* @internal */
|
||||
export function hasInitializer(node: Node): node is HasInitializer {
|
||||
return !!(node as HasInitializer).initializer;
|
||||
}
|
||||
|
||||
/** True if has initializer node attached to it. */
|
||||
/* @internal */
|
||||
export function hasOnlyExpressionInitializer(node: Node): node is HasExpressionInitializer {
|
||||
return hasInitializer(node) && !isForStatement(node) && !isForInStatement(node) && !isForOfStatement(node) && !isJsxAttribute(node);
|
||||
}
|
||||
}
|
||||
|
||||
+20
-1
@@ -48,6 +48,15 @@ namespace ts {
|
||||
};
|
||||
}
|
||||
|
||||
/** @internal */
|
||||
export function createWatchDiagnosticReporterWithColor(system = sys): DiagnosticReporter {
|
||||
return diagnostic => {
|
||||
let output = `[${ formatColorAndReset(new Date().toLocaleTimeString(), ForegroundColorEscapeSequences.Grey) }] `;
|
||||
output += `${flattenDiagnosticMessageText(diagnostic.messageText, system.newLine)}${system.newLine + system.newLine + system.newLine}`;
|
||||
system.write(output);
|
||||
};
|
||||
}
|
||||
|
||||
export function reportDiagnostics(diagnostics: Diagnostic[], reportDiagnostic: DiagnosticReporter): void {
|
||||
for (const diagnostic of diagnostics) {
|
||||
reportDiagnostic(diagnostic);
|
||||
@@ -131,7 +140,7 @@ namespace ts {
|
||||
reportWatchDiagnostic?: DiagnosticReporter
|
||||
): WatchingSystemHost {
|
||||
reportDiagnostic = reportDiagnostic || createDiagnosticReporter(system, pretty ? reportDiagnosticWithColorAndContext : reportDiagnosticSimply);
|
||||
reportWatchDiagnostic = reportWatchDiagnostic || createWatchDiagnosticReporter(system);
|
||||
reportWatchDiagnostic = reportWatchDiagnostic || pretty ? createWatchDiagnosticReporterWithColor(system) : createWatchDiagnosticReporter(system);
|
||||
parseConfigFile = parseConfigFile || ts.parseConfigFile;
|
||||
return {
|
||||
system,
|
||||
@@ -302,6 +311,8 @@ namespace ts {
|
||||
// There is no extra check needed since we can just rely on the program to decide emit
|
||||
const builder = createBuilder({ getCanonicalFileName, computeHash });
|
||||
|
||||
clearHostScreen();
|
||||
reportWatchDiagnostic(createCompilerDiagnostic(Diagnostics.Starting_compilation_in_watch_mode));
|
||||
synchronizeProgram();
|
||||
|
||||
// Update the wild card directory watch
|
||||
@@ -492,7 +503,15 @@ namespace ts {
|
||||
scheduleProgramUpdate();
|
||||
}
|
||||
|
||||
function clearHostScreen() {
|
||||
if (watchingHost.system.clearScreen) {
|
||||
watchingHost.system.clearScreen();
|
||||
}
|
||||
}
|
||||
|
||||
function updateProgram() {
|
||||
clearHostScreen();
|
||||
|
||||
timerToUpdateProgram = undefined;
|
||||
reportWatchDiagnostic(createCompilerDiagnostic(Diagnostics.File_change_detected_Starting_incremental_compilation));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user