diff --git a/lib/enu/diagnosticMessages.generated.json.lcg b/lib/enu/diagnosticMessages.generated.json.lcg
index d6970a39e90e7..b5e8bd17fdb5e 100644
--- a/lib/enu/diagnosticMessages.generated.json.lcg
+++ b/lib/enu/diagnosticMessages.generated.json.lcg
@@ -2253,12 +2253,6 @@
- -
-
-
-
-
-
-
@@ -2325,6 +2319,12 @@
+ -
+
+
+
+
+
-
@@ -4689,6 +4689,12 @@
+ -
+
+
+
+
+
-
@@ -5979,12 +5985,6 @@
- -
-
-
-
-
-
-
diff --git a/lib/lib.es5.d.ts b/lib/lib.es5.d.ts
index 50c0326ee1bce..0f5a66d958e1d 100644
--- a/lib/lib.es5.d.ts
+++ b/lib/lib.es5.d.ts
@@ -607,7 +607,7 @@ interface TemplateStringsArray extends ReadonlyArray {
/**
* The type of `import.meta`.
- *
+ *
* If you need to declare that a given property exists on `import.meta`,
* this type may be augmented via interface merging.
*/
@@ -1933,13 +1933,19 @@ interface Int8ArrayConstructor {
*/
of(...items: number[]): Int8Array;
+ /**
+ * Creates an array from an array-like or iterable object.
+ * @param arrayLike An array-like or iterable object to convert to an array.
+ */
+ from(arrayLike: ArrayLike): Int8Array;
+
/**
* Creates an array from an array-like or iterable object.
* @param arrayLike An array-like or iterable object to convert to an array.
* @param mapfn A mapping function to call on every element of the array.
* @param thisArg Value of 'this' used to invoke the mapfn.
*/
- from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Int8Array;
+ from(arrayLike: ArrayLike, mapfn: (v: T, k: number) => number, thisArg?: any): Int8Array;
}
@@ -2203,13 +2209,19 @@ interface Uint8ArrayConstructor {
*/
of(...items: number[]): Uint8Array;
+ /**
+ * Creates an array from an array-like or iterable object.
+ * @param arrayLike An array-like or iterable object to convert to an array.
+ */
+ from(arrayLike: ArrayLike): Uint8Array;
+
/**
* Creates an array from an array-like or iterable object.
* @param arrayLike An array-like or iterable object to convert to an array.
* @param mapfn A mapping function to call on every element of the array.
* @param thisArg Value of 'this' used to invoke the mapfn.
*/
- from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8Array;
+ from(arrayLike: ArrayLike, mapfn: (v: T, k: number) => number, thisArg?: any): Uint8Array;
}
declare const Uint8Array: Uint8ArrayConstructor;
@@ -2472,13 +2484,19 @@ interface Uint8ClampedArrayConstructor {
*/
of(...items: number[]): Uint8ClampedArray;
+ /**
+ * Creates an array from an array-like or iterable object.
+ * @param arrayLike An array-like or iterable object to convert to an array.
+ */
+ from(arrayLike: ArrayLike): Uint8ClampedArray;
+
/**
* Creates an array from an array-like or iterable object.
* @param arrayLike An array-like or iterable object to convert to an array.
* @param mapfn A mapping function to call on every element of the array.
* @param thisArg Value of 'this' used to invoke the mapfn.
*/
- from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint8ClampedArray;
+ from(arrayLike: ArrayLike, mapfn: (v: T, k: number) => number, thisArg?: any): Uint8ClampedArray;
}
declare const Uint8ClampedArray: Uint8ClampedArrayConstructor;
@@ -2739,13 +2757,19 @@ interface Int16ArrayConstructor {
*/
of(...items: number[]): Int16Array;
+ /**
+ * Creates an array from an array-like or iterable object.
+ * @param arrayLike An array-like or iterable object to convert to an array.
+ */
+ from(arrayLike: ArrayLike): Int16Array;
+
/**
* Creates an array from an array-like or iterable object.
* @param arrayLike An array-like or iterable object to convert to an array.
* @param mapfn A mapping function to call on every element of the array.
* @param thisArg Value of 'this' used to invoke the mapfn.
*/
- from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Int16Array;
+ from(arrayLike: ArrayLike, mapfn: (v: T, k: number) => number, thisArg?: any): Int16Array;
}
@@ -3009,13 +3033,19 @@ interface Uint16ArrayConstructor {
*/
of(...items: number[]): Uint16Array;
+ /**
+ * Creates an array from an array-like or iterable object.
+ * @param arrayLike An array-like or iterable object to convert to an array.
+ */
+ from(arrayLike: ArrayLike): Uint16Array;
+
/**
* Creates an array from an array-like or iterable object.
* @param arrayLike An array-like or iterable object to convert to an array.
* @param mapfn A mapping function to call on every element of the array.
* @param thisArg Value of 'this' used to invoke the mapfn.
*/
- from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint16Array;
+ from(arrayLike: ArrayLike, mapfn: (v: T, k: number) => number, thisArg?: any): Uint16Array;
}
@@ -3278,13 +3308,19 @@ interface Int32ArrayConstructor {
*/
of(...items: number[]): Int32Array;
+ /**
+ * Creates an array from an array-like or iterable object.
+ * @param arrayLike An array-like or iterable object to convert to an array.
+ */
+ from(arrayLike: ArrayLike): Int32Array;
+
/**
* Creates an array from an array-like or iterable object.
* @param arrayLike An array-like or iterable object to convert to an array.
* @param mapfn A mapping function to call on every element of the array.
* @param thisArg Value of 'this' used to invoke the mapfn.
*/
- from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Int32Array;
+ from(arrayLike: ArrayLike, mapfn: (v: T, k: number) => number, thisArg?: any): Int32Array;
}
declare const Int32Array: Int32ArrayConstructor;
@@ -3546,13 +3582,19 @@ interface Uint32ArrayConstructor {
*/
of(...items: number[]): Uint32Array;
+ /**
+ * Creates an array from an array-like or iterable object.
+ * @param arrayLike An array-like or iterable object to convert to an array.
+ */
+ from(arrayLike: ArrayLike): Uint32Array;
+
/**
* Creates an array from an array-like or iterable object.
* @param arrayLike An array-like or iterable object to convert to an array.
* @param mapfn A mapping function to call on every element of the array.
* @param thisArg Value of 'this' used to invoke the mapfn.
*/
- from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Uint32Array;
+ from(arrayLike: ArrayLike, mapfn: (v: T, k: number) => number, thisArg?: any): Uint32Array;
}
declare const Uint32Array: Uint32ArrayConstructor;
@@ -3815,13 +3857,19 @@ interface Float32ArrayConstructor {
*/
of(...items: number[]): Float32Array;
+ /**
+ * Creates an array from an array-like or iterable object.
+ * @param arrayLike An array-like or iterable object to convert to an array.
+ */
+ from(arrayLike: ArrayLike): Float32Array;
+
/**
* Creates an array from an array-like or iterable object.
* @param arrayLike An array-like or iterable object to convert to an array.
* @param mapfn A mapping function to call on every element of the array.
* @param thisArg Value of 'this' used to invoke the mapfn.
*/
- from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Float32Array;
+ from(arrayLike: ArrayLike, mapfn: (v: T, k: number) => number, thisArg?: any): Float32Array;
}
@@ -4085,13 +4133,19 @@ interface Float64ArrayConstructor {
*/
of(...items: number[]): Float64Array;
+ /**
+ * Creates an array from an array-like or iterable object.
+ * @param arrayLike An array-like or iterable object to convert to an array.
+ */
+ from(arrayLike: ArrayLike): Float64Array;
+
/**
* Creates an array from an array-like or iterable object.
* @param arrayLike An array-like or iterable object to convert to an array.
* @param mapfn A mapping function to call on every element of the array.
* @param thisArg Value of 'this' used to invoke the mapfn.
*/
- from(arrayLike: ArrayLike, mapfn?: (v: number, k: number) => number, thisArg?: any): Float64Array;
+ from(arrayLike: ArrayLike, mapfn: (v: T, k: number) => number, thisArg?: any): Float64Array;
}
declare const Float64Array: Float64ArrayConstructor;
diff --git a/lib/protocol.d.ts b/lib/protocol.d.ts
index b02f7ae70d59a..66ad7eb215469 100644
--- a/lib/protocol.d.ts
+++ b/lib/protocol.d.ts
@@ -2279,8 +2279,8 @@ declare namespace ts.server.protocol {
readonly importModuleSpecifierPreference?: "relative" | "non-relative";
readonly allowTextChangesInNewFiles?: boolean;
readonly lazyConfiguredProjectsFromExternalProject?: boolean;
- readonly allowRenameOfImportPath?: boolean;
readonly providePrefixAndSuffixTextForRename?: boolean;
+ readonly allowRenameOfImportPath?: boolean;
}
interface CompilerOptions {
allowJs?: boolean;
diff --git a/lib/tsc.js b/lib/tsc.js
index f90b479ba1c6d..2de7a3e73ef21 100644
--- a/lib/tsc.js
+++ b/lib/tsc.js
@@ -61,7 +61,7 @@ var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cook
var ts;
(function (ts) {
ts.versionMajorMinor = "3.3";
- ts.version = ts.versionMajorMinor + ".0-rc";
+ ts.version = ts.versionMajorMinor + ".1";
})(ts || (ts = {}));
(function (ts) {
ts.emptyArray = [];
@@ -3536,7 +3536,6 @@ var ts;
Property_0_is_used_before_being_assigned: diag(2565, ts.DiagnosticCategory.Error, "Property_0_is_used_before_being_assigned_2565", "Property '{0}' is used before being assigned."),
A_rest_element_cannot_have_a_property_name: diag(2566, ts.DiagnosticCategory.Error, "A_rest_element_cannot_have_a_property_name_2566", "A rest element cannot have a property name."),
Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations: diag(2567, ts.DiagnosticCategory.Error, "Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations_2567", "Enum declarations can only merge with namespace or other enum declarations."),
- Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators: diag(2568, ts.DiagnosticCategory.Error, "Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators_2568", "Type '{0}' is not an array type. Use compiler option '--downlevelIteration' to allow iterating of iterators."),
Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators: diag(2569, ts.DiagnosticCategory.Error, "Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterati_2569", "Type '{0}' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators."),
Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await: diag(2570, ts.DiagnosticCategory.Error, "Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await_2570", "Property '{0}' does not exist on type '{1}'. Did you forget to use 'await'?"),
Object_is_of_type_unknown: diag(2571, ts.DiagnosticCategory.Error, "Object_is_of_type_unknown_2571", "Object is of type 'unknown'."),
@@ -3631,7 +3630,7 @@ var ts;
Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor: diag(2715, ts.DiagnosticCategory.Error, "Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor_2715", "Abstract property '{0}' in class '{1}' cannot be accessed in the constructor."),
Type_parameter_0_has_a_circular_default: diag(2716, ts.DiagnosticCategory.Error, "Type_parameter_0_has_a_circular_default_2716", "Type parameter '{0}' has a circular default."),
Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_type_2: diag(2717, ts.DiagnosticCategory.Error, "Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_t_2717", "Subsequent property declarations must have the same type. Property '{0}' must be of type '{1}', but here has type '{2}'."),
- Duplicate_declaration_0: diag(2718, ts.DiagnosticCategory.Error, "Duplicate_declaration_0_2718", "Duplicate declaration '{0}'."),
+ Duplicate_property_0: diag(2718, ts.DiagnosticCategory.Error, "Duplicate_property_0_2718", "Duplicate property '{0}'."),
Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated: diag(2719, ts.DiagnosticCategory.Error, "Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated_2719", "Type '{0}' is not assignable to type '{1}'. Two different types with this name exist, but they are unrelated."),
Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass: diag(2720, ts.DiagnosticCategory.Error, "Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclas_2720", "Class '{0}' incorrectly implements class '{1}'. Did you mean to extend '{1}' and inherit its members as a subclass?"),
Cannot_invoke_an_object_which_is_possibly_null: diag(2721, ts.DiagnosticCategory.Error, "Cannot_invoke_an_object_which_is_possibly_null_2721", "Cannot invoke an object which is possibly 'null'."),
@@ -3646,6 +3645,7 @@ var ts;
An_arrow_function_cannot_have_a_this_parameter: diag(2730, ts.DiagnosticCategory.Error, "An_arrow_function_cannot_have_a_this_parameter_2730", "An arrow function cannot have a 'this' parameter."),
Implicit_conversion_of_a_symbol_to_a_string_will_fail_at_runtime_Consider_wrapping_this_expression_in_String: diag(2731, ts.DiagnosticCategory.Error, "Implicit_conversion_of_a_symbol_to_a_string_will_fail_at_runtime_Consider_wrapping_this_expression_i_2731", "Implicit conversion of a 'symbol' to a 'string' will fail at runtime. Consider wrapping this expression in 'String(...)'."),
Cannot_find_module_0_Consider_using_resolveJsonModule_to_import_module_with_json_extension: diag(2732, ts.DiagnosticCategory.Error, "Cannot_find_module_0_Consider_using_resolveJsonModule_to_import_module_with_json_extension_2732", "Cannot find module '{0}'. Consider using '--resolveJsonModule' to import module with '.json' extension"),
+ Property_0_was_also_declared_here: diag(2733, ts.DiagnosticCategory.Error, "Property_0_was_also_declared_here_2733", "Property '{0}' was also declared here."),
It_is_highly_likely_that_you_are_missing_a_semicolon: diag(2734, ts.DiagnosticCategory.Error, "It_is_highly_likely_that_you_are_missing_a_semicolon_2734", "It is highly likely that you are missing a semicolon."),
Did_you_mean_for_0_to_be_constrained_to_type_new_args_Colon_any_1: diag(2735, ts.DiagnosticCategory.Error, "Did_you_mean_for_0_to_be_constrained_to_type_new_args_Colon_any_1_2735", "Did you mean for '{0}' to be constrained to type 'new (...args: any[]) => {1}'?"),
Operator_0_cannot_be_applied_to_type_1: diag(2736, ts.DiagnosticCategory.Error, "Operator_0_cannot_be_applied_to_type_1_2736", "Operator '{0}' cannot be applied to type '{1}'."),
@@ -4810,6 +4810,7 @@ var ts;
scanJsxIdentifier: scanJsxIdentifier,
scanJsxAttributeValue: scanJsxAttributeValue,
reScanJsxToken: reScanJsxToken,
+ reScanLessThanToken: reScanLessThanToken,
scanJsxToken: scanJsxToken,
scanJSDocToken: scanJSDocToken,
scan: scan,
@@ -5751,6 +5752,13 @@ var ts;
pos = tokenPos = startPos;
return token = scanJsxToken();
}
+ function reScanLessThanToken() {
+ if (token === 46) {
+ pos = tokenPos + 1;
+ return token = 28;
+ }
+ return token;
+ }
function scanJsxToken() {
startPos = tokenPos = pos;
if (pos >= end) {
@@ -6583,7 +6591,9 @@ var ts;
case 14:
return ts.escapeLeadingUnderscores(name.text);
case 149:
- return isStringOrNumericLiteralLike(name.expression) ? ts.escapeLeadingUnderscores(name.expression.text) : undefined;
+ if (isStringOrNumericLiteralLike(name.expression))
+ return ts.escapeLeadingUnderscores(name.expression.text);
+ return ts.Debug.fail("Text of property name cannot be read from non-literal-valued ComputedPropertyNames");
default:
return ts.Debug.assertNever(name);
}
@@ -13837,6 +13847,9 @@ var ts;
function reScanTemplateToken() {
return currentToken = scanner.reScanTemplateToken();
}
+ function reScanLessThanToken() {
+ return currentToken = scanner.reScanLessThanToken();
+ }
function scanJsxIdentifier() {
return currentToken = scanner.scanJsxIdentifier();
}
@@ -14623,7 +14636,7 @@ var ts;
function parseTypeReference() {
var node = createNode(164);
node.typeName = parseEntityName(true, ts.Diagnostics.Type_expected);
- if (!scanner.hasPrecedingLineBreak() && token() === 28) {
+ if (!scanner.hasPrecedingLineBreak() && reScanLessThanToken() === 28) {
node.typeArguments = parseBracketedList(20, parseType, 28, 30);
}
return finishNode(node);
@@ -16169,7 +16182,7 @@ var ts;
function parseCallExpressionRest(expression) {
while (true) {
expression = parseMemberExpressionRest(expression);
- if (token() === 28) {
+ if (token() === 28 || token() === 46) {
var typeArguments = tryParse(parseTypeArgumentsInExpression);
if (!typeArguments) {
return expression;
@@ -16202,9 +16215,10 @@ var ts;
return result;
}
function parseTypeArgumentsInExpression() {
- if (!parseOptional(28)) {
+ if (reScanLessThanToken() !== 28) {
return undefined;
}
+ nextToken();
var typeArguments = parseDelimitedList(20, parseType);
if (!parseExpected(30)) {
return undefined;
@@ -22070,6 +22084,7 @@ var ts;
}
return 1;
}
+ var flowNodeCreated = ts.identity;
var binder = createBinder();
function bindSourceFile(file, options) {
ts.performance.mark("beforeBind");
@@ -22353,6 +22368,7 @@ var ts;
blockScopeContainer.locals = undefined;
}
if (containerFlags & 4) {
+ var saveFlowNodeCreated = flowNodeCreated;
var saveCurrentFlow = currentFlow;
var saveBreakTarget = currentBreakTarget;
var saveContinueTarget = currentContinueTarget;
@@ -22372,6 +22388,7 @@ var ts;
currentContinueTarget = undefined;
activeLabels = undefined;
hasExplicitReturn = false;
+ flowNodeCreated = ts.identity;
bindChildren(node);
node.flags &= ~1408;
if (!(currentFlow.flags & 1) && containerFlags & 8 && ts.nodeIsPresent(node.body)) {
@@ -22397,6 +22414,7 @@ var ts;
currentReturnTarget = saveReturnTarget;
activeLabels = saveActiveLabels;
hasExplicitReturn = saveHasExplicitReturn;
+ flowNodeCreated = saveFlowNodeCreated;
}
else if (containerFlags & 64) {
seenThisKeyword = false;
@@ -22658,22 +22676,22 @@ var ts;
return antecedent;
}
setFlowNodeReferenced(antecedent);
- return { flags: flags, expression: expression, antecedent: antecedent };
+ return flowNodeCreated({ flags: flags, expression: expression, antecedent: antecedent });
}
function createFlowSwitchClause(antecedent, switchStatement, clauseStart, clauseEnd) {
if (!isNarrowingExpression(switchStatement.expression)) {
return antecedent;
}
setFlowNodeReferenced(antecedent);
- return { flags: 128, switchStatement: switchStatement, clauseStart: clauseStart, clauseEnd: clauseEnd, antecedent: antecedent };
+ return flowNodeCreated({ flags: 128, switchStatement: switchStatement, clauseStart: clauseStart, clauseEnd: clauseEnd, antecedent: antecedent });
}
function createFlowAssignment(antecedent, node) {
setFlowNodeReferenced(antecedent);
- return { flags: 16, antecedent: antecedent, node: node };
+ return flowNodeCreated({ flags: 16, antecedent: antecedent, node: node });
}
function createFlowArrayMutation(antecedent, node) {
setFlowNodeReferenced(antecedent);
- var res = { flags: 256, antecedent: antecedent, node: node };
+ var res = flowNodeCreated({ flags: 256, antecedent: antecedent, node: node });
return res;
}
function finishFlowLabel(flow) {
@@ -22859,17 +22877,40 @@ var ts;
function bindTryStatement(node) {
var preFinallyLabel = createBranchLabel();
var preTryFlow = currentFlow;
+ var tryPriors = [];
+ var oldFlowNodeCreated = flowNodeCreated;
+ if (node.catchClause || node.finallyBlock) {
+ flowNodeCreated = function (node) { return (tryPriors.push(node), node); };
+ }
bind(node.tryBlock);
+ flowNodeCreated = oldFlowNodeCreated;
addAntecedent(preFinallyLabel, currentFlow);
var flowAfterTry = currentFlow;
var flowAfterCatch = unreachableFlow;
if (node.catchClause) {
currentFlow = preTryFlow;
+ if (tryPriors.length) {
+ var preCatchFlow = createBranchLabel();
+ addAntecedent(preCatchFlow, currentFlow);
+ for (var _i = 0, tryPriors_1 = tryPriors; _i < tryPriors_1.length; _i++) {
+ var p = tryPriors_1[_i];
+ addAntecedent(preCatchFlow, p);
+ }
+ currentFlow = finishFlowLabel(preCatchFlow);
+ }
bind(node.catchClause);
addAntecedent(preFinallyLabel, currentFlow);
flowAfterCatch = currentFlow;
}
if (node.finallyBlock) {
+ if (!node.catchClause) {
+ if (tryPriors.length) {
+ for (var _a = 0, tryPriors_2 = tryPriors; _a < tryPriors_2.length; _a++) {
+ var p = tryPriors_2[_a];
+ addAntecedent(preFinallyLabel, p);
+ }
+ }
+ }
var preFinallyFlow = { flags: 2048, antecedent: preTryFlow, lock: {} };
addAntecedent(preFinallyLabel, preFinallyFlow);
currentFlow = finishFlowLabel(preFinallyLabel);
@@ -22882,7 +22923,7 @@ var ts;
}
}
if (!(currentFlow.flags & 1)) {
- var afterFinallyFlow = { flags: 4096, antecedent: currentFlow };
+ var afterFinallyFlow = flowNodeCreated({ flags: 4096, antecedent: currentFlow });
preFinallyFlow.lock = afterFinallyFlow;
currentFlow = afterFinallyFlow;
}
@@ -29381,15 +29422,16 @@ var ts;
var objectFlags = 128;
ts.forEach(pattern.elements, function (e) {
var name = e.propertyName || e.name;
- if (isComputedNonLiteralName(name)) {
- objectFlags |= 512;
- return;
- }
if (e.dotDotDotToken) {
stringIndexInfo = createIndexInfo(anyType, false);
return;
}
- var text = ts.getTextOfPropertyName(name);
+ var exprType = getLiteralTypeFromPropertyName(name);
+ if (!isTypeUsableAsPropertyName(exprType)) {
+ objectFlags |= 512;
+ return;
+ }
+ var text = getPropertyNameFromType(exprType);
var flags = 4 | (e.initializer ? 16777216 : 0);
var symbol = createSymbol(flags, text);
symbol.type = getTypeFromBindingElement(e, includePatternInType, reportErrors);
@@ -30310,13 +30352,13 @@ var ts;
}
return type;
}
- function isTypeUsableAsLateBoundName(type) {
+ function isTypeUsableAsPropertyName(type) {
return !!(type.flags & 8576);
}
function isLateBindableName(node) {
return ts.isComputedPropertyName(node)
&& ts.isEntityNameExpression(node.expression)
- && isTypeUsableAsLateBoundName(checkComputedPropertyName(node));
+ && isTypeUsableAsPropertyName(checkComputedPropertyName(node));
}
function isLateBoundName(name) {
return name.charCodeAt(0) === 95 &&
@@ -30333,9 +30375,9 @@ var ts;
function isNonBindableDynamicName(node) {
return ts.isDynamicName(node) && !isLateBindableName(node);
}
- function getLateBoundNameFromType(type) {
+ function getPropertyNameFromType(type) {
if (type.flags & 8192) {
- return "__@" + type.symbol.escapedName + "@" + getSymbolId(type.symbol);
+ return type.escapedName;
}
if (type.flags & (128 | 256)) {
return ts.escapeLeadingUnderscores("" + type.value);
@@ -30364,8 +30406,8 @@ var ts;
if (!links.resolvedSymbol) {
links.resolvedSymbol = decl.symbol;
var type = checkComputedPropertyName(decl.name);
- if (isTypeUsableAsLateBoundName(type)) {
- var memberName = getLateBoundNameFromType(type);
+ if (isTypeUsableAsPropertyName(type)) {
+ var memberName = getPropertyNameFromType(type);
var symbolFlags = decl.symbol.flags;
var lateSymbol = lateSymbols.get(memberName);
if (!lateSymbol)
@@ -30373,9 +30415,9 @@ var ts;
var earlySymbol = earlySymbols && earlySymbols.get(memberName);
if (lateSymbol.flags & getExcludedSymbolFlags(symbolFlags) || earlySymbol) {
var declarations = earlySymbol ? ts.concatenate(earlySymbol.declarations, lateSymbol.declarations) : lateSymbol.declarations;
- var name_3 = ts.declarationNameToString(decl.name);
- ts.forEach(declarations, function (declaration) { return error(ts.getNameOfDeclaration(declaration) || declaration, ts.Diagnostics.Duplicate_declaration_0, name_3); });
- error(decl.name || decl, ts.Diagnostics.Duplicate_declaration_0, name_3);
+ var name_3 = !(type.flags & 8192) && ts.unescapeLeadingUnderscores(memberName) || ts.declarationNameToString(decl.name);
+ ts.forEach(declarations, function (declaration) { return error(ts.getNameOfDeclaration(declaration) || declaration, ts.Diagnostics.Property_0_was_also_declared_here, name_3); });
+ error(decl.name || decl, ts.Diagnostics.Duplicate_property_0, name_3);
lateSymbol = createSymbol(0, memberName, 2048);
}
lateSymbol.nameType = type;
@@ -30900,8 +30942,8 @@ var ts;
function addMemberForKeyType(t) {
var templateMapper = combineTypeMappers(type.mapper, createTypeMapper([typeParameter], [t]));
var propType = instantiateType(templateType, templateMapper);
- if (t.flags & 8576) {
- var propName = getLateBoundNameFromType(t);
+ if (isTypeUsableAsPropertyName(t)) {
+ var propName = getPropertyNameFromType(t);
var modifiersProp = getPropertyOfType(modifiersType, propName);
var isOptional = !!(templateModifiers & 4 ||
!(templateModifiers & 8) && modifiersProp && modifiersProp.flags & 16777216);
@@ -31056,7 +31098,8 @@ var ts;
function isTypeInvalidDueToUnionDiscriminant(contextualType, obj) {
var list = obj.properties;
return list.some(function (property) {
- var name = property.name && ts.getTextOfPropertyName(property.name);
+ var nameType = property.name && getLiteralTypeFromPropertyName(property.name);
+ var name = nameType && isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined;
var expected = name === undefined ? undefined : getTypeOfPropertyOfType(contextualType, name);
return !!expected && isLiteralType(expected) && !isTypeIdenticalTo(getTypeOfNode(property), expected);
});
@@ -31380,6 +31423,9 @@ var ts;
result.containingType = containingType;
if (!hasNonUniformValueDeclaration && firstValueDeclaration) {
result.valueDeclaration = firstValueDeclaration;
+ if (firstValueDeclaration.symbol.parent) {
+ result.parent = firstValueDeclaration.symbol.parent;
+ }
}
result.declarations = declarations;
result.nameType = nameType;
@@ -32138,20 +32184,12 @@ var ts;
return getTypeOfSymbol(symbol);
}
function getJSDocTypeReference(node, symbol, typeArguments) {
- if (!pushTypeResolution(symbol, 6)) {
- return errorType;
- }
- var assignedType = getAssignedClassType(symbol);
- var valueType = getTypeOfSymbol(symbol);
- var referenceType = valueType.symbol && valueType.symbol !== symbol && !isInferredClassType(valueType) && getTypeReferenceTypeWorker(node, valueType.symbol, typeArguments);
- if (!popTypeResolution()) {
- getSymbolLinks(symbol).resolvedJSDocType = errorType;
- error(node, ts.Diagnostics.JSDoc_type_0_circularly_references_itself, symbolToString(symbol));
- return errorType;
- }
- if (referenceType || assignedType) {
- var type = (referenceType && assignedType ? getIntersectionType([assignedType, referenceType]) : referenceType || assignedType);
- return getSymbolLinks(symbol).resolvedJSDocType = type;
+ var staticType = getTypeOfSymbol(symbol);
+ var instanceType = staticType.symbol &&
+ staticType.symbol !== symbol &&
+ getTypeReferenceTypeWorker(node, staticType.symbol, typeArguments);
+ if (instanceType) {
+ return getSymbolLinks(symbol).resolvedJSDocType = instanceType;
}
}
function getTypeReferenceTypeWorker(node, symbol, typeArguments) {
@@ -32169,8 +32207,11 @@ var ts;
}
if (symbol.flags & 16 &&
isJSDocTypeReference(node) &&
- (symbol.members || ts.getJSDocClassTag(symbol.valueDeclaration))) {
- return getInferredClassType(symbol);
+ isJSConstructor(symbol.valueDeclaration)) {
+ var resolved = resolveStructuredTypeMembers(getTypeOfSymbol(symbol));
+ if (resolved.callSignatures.length === 1) {
+ return getReturnTypeOfSignature(resolved.callSignatures[0]);
+ }
}
}
function getSubstitutionType(typeVariable, substitute) {
@@ -32980,8 +33021,8 @@ var ts;
}
function getPropertyTypeForIndexType(objectType, indexType, accessNode, cacheSymbol, missingType) {
var accessExpression = accessNode && accessNode.kind === 190 ? accessNode : undefined;
- var propName = isTypeUsableAsLateBoundName(indexType) ?
- getLateBoundNameFromType(indexType) :
+ var propName = isTypeUsableAsPropertyName(indexType) ?
+ getPropertyNameFromType(indexType) :
accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, false) ?
ts.getPropertyNameForKnownSymbolName(ts.idText(accessExpression.argumentExpression.name)) :
accessNode && ts.isPropertyName(accessNode) ?
@@ -33566,6 +33607,7 @@ var ts;
function createUniqueESSymbolType(symbol) {
var type = createType(8192);
type.symbol = symbol;
+ type.escapedName = "__@" + type.symbol.escapedName + "@" + getSymbolId(type.symbol);
return type;
}
function getESSymbolLikeTypeForNode(node) {
@@ -33757,7 +33799,9 @@ var ts;
return type.flags & 262144 ? wildcardType : type;
}
function getRestrictiveTypeParameter(tp) {
- return !tp.constraint ? tp : tp.restrictiveInstantiation || (tp.restrictiveInstantiation = createTypeParameter(tp.symbol));
+ return tp.constraint === unknownType ? tp : tp.restrictiveInstantiation || (tp.restrictiveInstantiation = createTypeParameter(tp.symbol),
+ tp.restrictiveInstantiation.constraint = unknownType,
+ tp.restrictiveInstantiation);
}
function restrictiveMapper(type) {
return type.flags & 262144 ? getRestrictiveTypeParameter(type) : type;
@@ -34277,7 +34321,7 @@ var ts;
}
if (resultObj.error) {
var reportedDiag = resultObj.error;
- var propertyName = isTypeUsableAsLateBoundName(nameType) ? getLateBoundNameFromType(nameType) : undefined;
+ var propertyName = isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined;
var targetProp = propertyName !== undefined ? getPropertyOfType(target, propertyName) : undefined;
var issuedElaboration = false;
if (!targetProp) {
@@ -35477,7 +35521,7 @@ var ts;
}
}
else {
- if (isPartialMappedType(target) && isEmptyObjectType(source)) {
+ if (relation !== subtypeRelation && isPartialMappedType(target) && isEmptyObjectType(source)) {
return -1;
}
if (isGenericMappedType(target)) {
@@ -37038,7 +37082,11 @@ var ts;
priority |= 4;
inferFromTypes(getIndexType(source), constraintType);
priority = savePriority;
- inferFromTypes(getUnionType(ts.map(getPropertiesOfType(source), getTypeOfSymbol)), getTemplateTypeFromMappedType(target));
+ var valueTypes = ts.compact([
+ getIndexTypeOfType(source, 0),
+ getIndexTypeOfType(source, 1)
+ ].concat(ts.map(getPropertiesOfType(source), getTypeOfSymbol)));
+ inferFromTypes(getUnionType(valueTypes), getTemplateTypeFromMappedType(target));
return true;
}
return false;
@@ -37546,7 +37594,10 @@ var ts;
return type;
}
function getTypeOfDestructuredProperty(type, name) {
- var text = ts.getTextOfPropertyName(name);
+ var nameType = getLiteralTypeFromPropertyName(name);
+ if (!isTypeUsableAsPropertyName(nameType))
+ return errorType;
+ var text = getPropertyNameFromType(nameType);
return getConstraintForLocation(getTypeOfPropertyOfType(type, text), name) ||
isNumericLiteralName(text) && getIndexTypeOfType(type, 1) ||
getIndexTypeOfType(type, 0) ||
@@ -38048,9 +38099,6 @@ var ts;
}
function getTypeAtSwitchClause(flow) {
var expr = flow.switchStatement.expression;
- if (containsMatchingReferenceDiscriminant(reference, expr)) {
- return declaredType;
- }
var flowType = getTypeAtFlowNode(flow.antecedent);
var type = getTypeFromFlowType(flowType);
if (isMatchingReference(reference, expr)) {
@@ -38062,6 +38110,9 @@ var ts;
else if (expr.kind === 199 && isMatchingReference(reference, expr.expression)) {
type = narrowBySwitchOnTypeOf(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd);
}
+ else if (containsMatchingReferenceDiscriminant(reference, expr)) {
+ type = declaredType;
+ }
return createFlowType(type, isIncomplete(flowType));
}
function getTypeAtFlowBranchLabel(flow) {
@@ -38870,7 +38921,7 @@ var ts;
else if (isInJS &&
(container.kind === 196 || container.kind === 239) &&
ts.getJSDocClassTag(container)) {
- var classType = getJSClassType(container.symbol);
+ var classType = getJSClassType(getMergedSymbol(container.symbol));
if (classType) {
return getFlowTypeOfReference(node, classType);
}
@@ -39166,9 +39217,10 @@ var ts;
var parentDeclaration = declaration.parent.parent;
var name = declaration.propertyName || declaration.name;
var parentType = getContextualTypeForVariableLikeDeclaration(parentDeclaration);
- if (parentType && !ts.isBindingPattern(name)) {
- var text = ts.getTextOfPropertyName(name);
- if (text !== undefined) {
+ if (parentType && !ts.isBindingPattern(name) && !isComputedNonLiteralName(name)) {
+ var nameType = getLiteralTypeFromPropertyName(name);
+ if (isTypeUsableAsPropertyName(nameType)) {
+ var text = getPropertyNameFromType(nameType);
return getTypeOfPropertyOfType(parentType, text);
}
}
@@ -39910,10 +39962,9 @@ var ts;
}
}
typeFlags |= type.flags;
- var nameType = computedNameType && computedNameType.flags & 8576 ?
- computedNameType : undefined;
+ var nameType = computedNameType && isTypeUsableAsPropertyName(computedNameType) ? computedNameType : undefined;
var prop = nameType ?
- createSymbol(4 | member.flags, getLateBoundNameFromType(nameType), 2048) :
+ createSymbol(4 | member.flags, getPropertyNameFromType(nameType), 2048) :
createSymbol(4 | member.flags, member.escapedName);
if (nameType) {
prop.nameType = nameType;
@@ -40136,6 +40187,9 @@ var ts;
childrenPropSymbol.type = childrenTypes.length === 1 ?
childrenTypes[0] :
(getArrayLiteralTupleTypeIfApplicable(childrenTypes, childrenContextualType, false) || createArrayType(getUnionType(childrenTypes)));
+ childrenPropSymbol.valueDeclaration = ts.createPropertySignature(undefined, ts.unescapeLeadingUnderscores(jsxChildrenPropertyName), undefined, undefined, undefined);
+ childrenPropSymbol.valueDeclaration.parent = attributes;
+ childrenPropSymbol.valueDeclaration.symbol = childrenPropSymbol;
var childPropMap = ts.createSymbolTable();
childPropMap.set(jsxChildrenPropertyName, childrenPropSymbol);
spread = getSpreadType(spread, createAnonymousType(attributes.symbol, childPropMap, ts.emptyArray, ts.emptyArray, undefined, undefined), attributes.symbol, typeFlags, objectFlags);
@@ -41491,6 +41545,10 @@ var ts;
if (inferenceContext) {
var typeArgumentTypes = inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext);
checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration));
+ if (getNonArrayRestType(candidate) && !hasCorrectArity(node, args, checkCandidate, signatureHelpTrailingComma)) {
+ candidateForArgumentArityError = checkCandidate;
+ continue;
+ }
}
if (!checkApplicableSignature(node, args, checkCandidate, relation, excludeArgument, false)) {
if (!candidateForArgumentError || getEffectiveRestType(candidateForArgumentError) || !getEffectiveRestType(checkCandidate)) {
@@ -41934,7 +41992,7 @@ var ts;
if (ts.getJSDocClassTag(node))
return true;
var symbol = getSymbolOfNode(func);
- return !!symbol && symbol.members !== undefined;
+ return !!symbol && (symbol.members !== undefined || symbol.exports !== undefined && symbol.exports.get("prototype") !== undefined);
}
return false;
}
@@ -41951,10 +42009,6 @@ var ts;
inferred = getInferredClassType(symbol);
}
var assigned = getAssignedClassType(symbol);
- var valueType = getTypeOfSymbol(symbol);
- if (valueType.symbol && !isInferredClassType(valueType) && isJSConstructor(valueType.symbol.valueDeclaration)) {
- inferred = getInferredClassType(valueType.symbol);
- }
return assigned && inferred ?
getIntersectionType([inferred, assigned]) :
assigned || inferred;
@@ -41989,11 +42043,6 @@ var ts;
}
return links.inferredClassType;
}
- function isInferredClassType(type) {
- return type.symbol
- && ts.getObjectFlags(type) & 16
- && getSymbolLinks(type.symbol).inferredClassType === type;
- }
function checkCallExpression(node) {
if (!checkGrammarTypeArguments(node, node.typeArguments))
checkGrammarArguments(node.arguments);
@@ -42007,15 +42056,8 @@ var ts;
declaration.kind !== 157 &&
declaration.kind !== 161 &&
declaration.kind !== 166 &&
- !ts.isJSDocConstructSignature(declaration)) {
- var funcSymbol = checkExpression(node.expression).symbol;
- if (!funcSymbol && node.expression.kind === 72) {
- funcSymbol = getResolvedSymbol(node.expression);
- }
- var type = funcSymbol && getJSClassType(funcSymbol);
- if (type) {
- return signature.target ? instantiateType(type, signature.mapper) : type;
- }
+ !ts.isJSDocConstructSignature(declaration) &&
+ !isJSConstructor(declaration)) {
if (noImplicitAny) {
error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type);
}
@@ -42946,7 +42988,7 @@ var ts;
if (!(isTypeComparableTo(leftType, stringType) || isTypeAssignableToKind(leftType, 296 | 12288))) {
error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol);
}
- if (!isTypeAssignableToKind(rightType, 67108864 | 58982400)) {
+ if (!allTypesAssignableToKind(rightType, 67108864 | 58982400)) {
error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
}
return booleanType;
@@ -42966,15 +43008,15 @@ var ts;
if (rightIsThis === void 0) { rightIsThis = false; }
if (property.kind === 275 || property.kind === 276) {
var name = property.name;
- var text = ts.getTextOfPropertyName(name);
- if (text) {
+ var exprType = getLiteralTypeFromPropertyName(name);
+ if (isTypeUsableAsPropertyName(exprType)) {
+ var text = getPropertyNameFromType(exprType);
var prop = getPropertyOfType(objectLiteralType, text);
if (prop) {
markPropertyAsReferenced(prop, property, rightIsThis);
checkPropertyAccessibility(property, false, objectLiteralType, prop);
}
}
- var exprType = getLiteralTypeFromPropertyName(name);
var elementType = getIndexedAccessType(objectLiteralType, exprType, name);
var type = getFlowTypeOfDestructuring(property, elementType);
return checkDestructuringAssignment(property.kind === 276 ? property : property.initializer, type);
@@ -45499,9 +45541,10 @@ var ts;
var parent = node.parent.parent;
var parentType = getTypeForBindingElementParent(parent);
var name = node.propertyName || node.name;
- if (!ts.isBindingPattern(name)) {
- var nameText = ts.getTextOfPropertyName(name);
- if (nameText) {
+ if (!ts.isBindingPattern(name) && parentType) {
+ var exprType = getLiteralTypeFromPropertyName(name);
+ if (isTypeUsableAsPropertyName(exprType)) {
+ var nameText = getPropertyNameFromType(exprType);
var property = getPropertyOfType(parentType, nameText);
if (property) {
markPropertyAsReferenced(property, undefined, false);
@@ -45793,7 +45836,7 @@ var ts;
? downlevelIteration
? ts.Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator
: isIterable
- ? ts.Diagnostics.Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators
+ ? ts.Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators
: ts.Diagnostics.Type_0_is_not_an_array_type
: downlevelIteration
? ts.Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator
@@ -49896,6 +49939,7 @@ var ts;
if (nodeArguments.length !== 1) {
return grammarErrorOnNode(node, ts.Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument);
}
+ checkGrammarForDisallowedTrailingComma(nodeArguments);
if (ts.isSpreadElement(nodeArguments[0])) {
return grammarErrorOnNode(nodeArguments[0], ts.Diagnostics.Specifier_of_dynamic_import_cannot_be_spread_element);
}
@@ -52251,22 +52295,62 @@ var ts;
return node;
}
ts.createBundle = createBundle;
- function createUnparsedSourceFile(text, mapPath, map) {
+ function createUnparsedSourceFile(textOrInputFiles, mapPathOrType, map) {
var node = ts.createNode(281);
- node.text = text;
- node.sourceMapPath = mapPath;
- node.sourceMapText = map;
+ if (!ts.isString(textOrInputFiles)) {
+ ts.Debug.assert(mapPathOrType === "js" || mapPathOrType === "dts");
+ node.fileName = mapPathOrType === "js" ? textOrInputFiles.javascriptPath : textOrInputFiles.declarationPath;
+ node.sourceMapPath = mapPathOrType === "js" ? textOrInputFiles.javascriptMapPath : textOrInputFiles.declarationMapPath;
+ Object.defineProperties(node, {
+ text: { get: function () { return mapPathOrType === "js" ? textOrInputFiles.javascriptText : textOrInputFiles.declarationText; } },
+ sourceMapText: { get: function () { return mapPathOrType === "js" ? textOrInputFiles.javascriptMapText : textOrInputFiles.declarationMapText; } },
+ });
+ }
+ else {
+ node.text = textOrInputFiles;
+ node.sourceMapPath = mapPathOrType;
+ node.sourceMapText = map;
+ }
return node;
}
ts.createUnparsedSourceFile = createUnparsedSourceFile;
- function createInputFiles(javascript, declaration, javascriptMapPath, javascriptMapText, declarationMapPath, declarationMapText) {
+ function createInputFiles(javascriptTextOrReadFileText, declarationTextOrJavascriptPath, javascriptMapPath, javascriptMapTextOrDeclarationPath, declarationMapPath, declarationMapText) {
var node = ts.createNode(282);
- node.javascriptText = javascript;
- node.javascriptMapPath = javascriptMapPath;
- node.javascriptMapText = javascriptMapText;
- node.declarationText = declaration;
- node.declarationMapPath = declarationMapPath;
- node.declarationMapText = declarationMapText;
+ if (!ts.isString(javascriptTextOrReadFileText)) {
+ var cache_1 = ts.createMap();
+ var textGetter_1 = function (path) {
+ if (path === undefined)
+ return undefined;
+ var value = cache_1.get(path);
+ if (value === undefined) {
+ value = javascriptTextOrReadFileText(path);
+ cache_1.set(path, value !== undefined ? value : false);
+ }
+ return value !== false ? value : undefined;
+ };
+ var definedTextGetter_1 = function (path) {
+ var result = textGetter_1(path);
+ return result !== undefined ? result : "/* Input file " + path + " was missing */\r\n";
+ };
+ node.javascriptPath = declarationTextOrJavascriptPath;
+ node.javascriptMapPath = javascriptMapPath;
+ node.declarationPath = ts.Debug.assertDefined(javascriptMapTextOrDeclarationPath);
+ node.declarationMapPath = declarationMapPath;
+ Object.defineProperties(node, {
+ javascriptText: { get: function () { return definedTextGetter_1(declarationTextOrJavascriptPath); } },
+ javascriptMapText: { get: function () { return textGetter_1(javascriptMapPath); } },
+ declarationText: { get: function () { return definedTextGetter_1(ts.Debug.assertDefined(javascriptMapTextOrDeclarationPath)); } },
+ declarationMapText: { get: function () { return textGetter_1(declarationMapPath); } }
+ });
+ }
+ else {
+ node.javascriptText = javascriptTextOrReadFileText;
+ node.javascriptMapPath = javascriptMapPath;
+ node.javascriptMapText = javascriptMapTextOrDeclarationPath;
+ node.declarationText = declarationTextOrJavascriptPath;
+ node.declarationMapPath = declarationMapPath;
+ node.declarationMapText = declarationMapText;
+ }
return node;
}
ts.createInputFiles = createInputFiles;
@@ -55790,7 +55874,7 @@ var ts;
function transformBundle(node) {
return ts.createBundle(node.sourceFiles.map(transformSourceFile), ts.mapDefined(node.prepends, function (prepend) {
if (prepend.kind === 282) {
- return ts.createUnparsedSourceFile(prepend.javascriptText, prepend.javascriptMapPath, prepend.javascriptMapText);
+ return ts.createUnparsedSourceFile(prepend, "js");
}
return prepend;
}));
@@ -65175,7 +65259,7 @@ var ts;
return ts.updateSourceFileNode(sourceFile, transformAndReplaceLatePaintedStatements(updated), true, [], [], false, []);
}), ts.mapDefined(node.prepends, function (prepend) {
if (prepend.kind === 282) {
- return ts.createUnparsedSourceFile(prepend.declarationText, prepend.declarationMapPath, prepend.declarationMapText);
+ return ts.createUnparsedSourceFile(prepend, "dts");
}
}));
bundle.syntheticFileReferences = [];
@@ -66358,16 +66442,20 @@ var ts;
}
}
ts.forEachEmittedFile = forEachEmittedFile;
+ function getOutputPathsForBundle(options, forceDtsPaths) {
+ var outPath = options.outFile || options.out;
+ var jsFilePath = options.emitDeclarationOnly ? undefined : outPath;
+ var sourceMapFilePath = jsFilePath && getSourceMapFilePath(jsFilePath, options);
+ var declarationFilePath = (forceDtsPaths || ts.getEmitDeclarations(options)) ? ts.removeFileExtension(outPath) + ".d.ts" : undefined;
+ var declarationMapPath = declarationFilePath && ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
+ var bundleInfoPath = options.references && jsFilePath ? (ts.removeFileExtension(jsFilePath) + infoExtension) : undefined;
+ return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: bundleInfoPath };
+ }
+ ts.getOutputPathsForBundle = getOutputPathsForBundle;
function getOutputPathsFor(sourceFile, host, forceDtsPaths) {
var options = host.getCompilerOptions();
if (sourceFile.kind === 280) {
- var outPath = options.outFile || options.out;
- var jsFilePath = options.emitDeclarationOnly ? undefined : outPath;
- var sourceMapFilePath = jsFilePath && getSourceMapFilePath(jsFilePath, options);
- var declarationFilePath = (forceDtsPaths || ts.getEmitDeclarations(options)) ? ts.removeFileExtension(outPath) + ".d.ts" : undefined;
- var declarationMapPath = declarationFilePath && ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
- var bundleInfoPath = options.references && jsFilePath ? (ts.removeFileExtension(jsFilePath) + infoExtension) : undefined;
- return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: bundleInfoPath };
+ return getOutputPathsForBundle(options, forceDtsPaths);
}
else {
var ownOutputFilePath = ts.getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options));
@@ -69832,7 +69920,7 @@ var ts;
}
}
function skipSourceTrivia(source, pos) {
- return source.skipTrivia ? source.skipTrivia(pos) : ts.skipTrivia(sourceMapSource.text, pos);
+ return source.skipTrivia ? source.skipTrivia(pos) : ts.skipTrivia(source.text, pos);
}
function emitPos(pos) {
if (sourceMapsDisabled || ts.positionIsSynthesized(pos) || isJsonSourceMapSource(sourceMapSource)) {
@@ -71264,14 +71352,12 @@ var ts;
var out = resolvedRefOpts.options.outFile || resolvedRefOpts.options.out;
if (!out)
continue;
- var dtsFilename = ts.changeExtension(out, ".d.ts");
- var js = host.readFile(out) || "/* Input file " + out + " was missing */\r\n";
- var jsMapPath = out + ".map";
- var jsMap = host.readFile(jsMapPath);
- var dts = host.readFile(dtsFilename) || "/* Input file " + dtsFilename + " was missing */\r\n";
- var dtsMapPath = dtsFilename + ".map";
- var dtsMap = host.readFile(dtsMapPath);
- var node = ts.createInputFiles(js, dts, jsMap && jsMapPath, jsMap, dtsMap && dtsMapPath, dtsMap);
+ var _a = ts.getOutputPathsForBundle(resolvedRefOpts.options, true), jsFilePath = _a.jsFilePath, sourceMapFilePath = _a.sourceMapFilePath, declarationFilePath = _a.declarationFilePath, declarationMapPath = _a.declarationMapPath;
+ var node = ts.createInputFiles(function (fileName) {
+ var path = toPath(fileName);
+ var sourceFile = getSourceFileByPath(path);
+ return sourceFile ? sourceFile.text : filesByName.has(path) ? undefined : host.readFile(path);
+ }, jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath);
nodes.push(node);
}
}
diff --git a/lib/tsserver.js b/lib/tsserver.js
index 4cf85b4c5f36c..93b04dacfaf94 100644
--- a/lib/tsserver.js
+++ b/lib/tsserver.js
@@ -88,7 +88,7 @@ var ts;
// If changing the text in this section, be sure to test `configureNightly` too.
ts.versionMajorMinor = "3.3";
/** The version of the TypeScript compiler release */
- ts.version = ts.versionMajorMinor + ".0-rc";
+ ts.version = ts.versionMajorMinor + ".1";
})(ts || (ts = {}));
(function (ts) {
/* @internal */
@@ -5533,7 +5533,6 @@ var ts;
Property_0_is_used_before_being_assigned: diag(2565, ts.DiagnosticCategory.Error, "Property_0_is_used_before_being_assigned_2565", "Property '{0}' is used before being assigned."),
A_rest_element_cannot_have_a_property_name: diag(2566, ts.DiagnosticCategory.Error, "A_rest_element_cannot_have_a_property_name_2566", "A rest element cannot have a property name."),
Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations: diag(2567, ts.DiagnosticCategory.Error, "Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations_2567", "Enum declarations can only merge with namespace or other enum declarations."),
- Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators: diag(2568, ts.DiagnosticCategory.Error, "Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators_2568", "Type '{0}' is not an array type. Use compiler option '--downlevelIteration' to allow iterating of iterators."),
Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators: diag(2569, ts.DiagnosticCategory.Error, "Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterati_2569", "Type '{0}' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators."),
Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await: diag(2570, ts.DiagnosticCategory.Error, "Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await_2570", "Property '{0}' does not exist on type '{1}'. Did you forget to use 'await'?"),
Object_is_of_type_unknown: diag(2571, ts.DiagnosticCategory.Error, "Object_is_of_type_unknown_2571", "Object is of type 'unknown'."),
@@ -5628,7 +5627,7 @@ var ts;
Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor: diag(2715, ts.DiagnosticCategory.Error, "Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor_2715", "Abstract property '{0}' in class '{1}' cannot be accessed in the constructor."),
Type_parameter_0_has_a_circular_default: diag(2716, ts.DiagnosticCategory.Error, "Type_parameter_0_has_a_circular_default_2716", "Type parameter '{0}' has a circular default."),
Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_type_2: diag(2717, ts.DiagnosticCategory.Error, "Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_t_2717", "Subsequent property declarations must have the same type. Property '{0}' must be of type '{1}', but here has type '{2}'."),
- Duplicate_declaration_0: diag(2718, ts.DiagnosticCategory.Error, "Duplicate_declaration_0_2718", "Duplicate declaration '{0}'."),
+ Duplicate_property_0: diag(2718, ts.DiagnosticCategory.Error, "Duplicate_property_0_2718", "Duplicate property '{0}'."),
Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated: diag(2719, ts.DiagnosticCategory.Error, "Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated_2719", "Type '{0}' is not assignable to type '{1}'. Two different types with this name exist, but they are unrelated."),
Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass: diag(2720, ts.DiagnosticCategory.Error, "Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclas_2720", "Class '{0}' incorrectly implements class '{1}'. Did you mean to extend '{1}' and inherit its members as a subclass?"),
Cannot_invoke_an_object_which_is_possibly_null: diag(2721, ts.DiagnosticCategory.Error, "Cannot_invoke_an_object_which_is_possibly_null_2721", "Cannot invoke an object which is possibly 'null'."),
@@ -5643,6 +5642,7 @@ var ts;
An_arrow_function_cannot_have_a_this_parameter: diag(2730, ts.DiagnosticCategory.Error, "An_arrow_function_cannot_have_a_this_parameter_2730", "An arrow function cannot have a 'this' parameter."),
Implicit_conversion_of_a_symbol_to_a_string_will_fail_at_runtime_Consider_wrapping_this_expression_in_String: diag(2731, ts.DiagnosticCategory.Error, "Implicit_conversion_of_a_symbol_to_a_string_will_fail_at_runtime_Consider_wrapping_this_expression_i_2731", "Implicit conversion of a 'symbol' to a 'string' will fail at runtime. Consider wrapping this expression in 'String(...)'."),
Cannot_find_module_0_Consider_using_resolveJsonModule_to_import_module_with_json_extension: diag(2732, ts.DiagnosticCategory.Error, "Cannot_find_module_0_Consider_using_resolveJsonModule_to_import_module_with_json_extension_2732", "Cannot find module '{0}'. Consider using '--resolveJsonModule' to import module with '.json' extension"),
+ Property_0_was_also_declared_here: diag(2733, ts.DiagnosticCategory.Error, "Property_0_was_also_declared_here_2733", "Property '{0}' was also declared here."),
It_is_highly_likely_that_you_are_missing_a_semicolon: diag(2734, ts.DiagnosticCategory.Error, "It_is_highly_likely_that_you_are_missing_a_semicolon_2734", "It is highly likely that you are missing a semicolon."),
Did_you_mean_for_0_to_be_constrained_to_type_new_args_Colon_any_1: diag(2735, ts.DiagnosticCategory.Error, "Did_you_mean_for_0_to_be_constrained_to_type_new_args_Colon_any_1_2735", "Did you mean for '{0}' to be constrained to type 'new (...args: any[]) => {1}'?"),
Operator_0_cannot_be_applied_to_type_1: diag(2736, ts.DiagnosticCategory.Error, "Operator_0_cannot_be_applied_to_type_1_2736", "Operator '{0}' cannot be applied to type '{1}'."),
@@ -6930,6 +6930,7 @@ var ts;
scanJsxIdentifier: scanJsxIdentifier,
scanJsxAttributeValue: scanJsxAttributeValue,
reScanJsxToken: reScanJsxToken,
+ reScanLessThanToken: reScanLessThanToken,
scanJsxToken: scanJsxToken,
scanJSDocToken: scanJSDocToken,
scan: scan,
@@ -7926,6 +7927,13 @@ var ts;
pos = tokenPos = startPos;
return token = scanJsxToken();
}
+ function reScanLessThanToken() {
+ if (token === 46 /* LessThanLessThanToken */) {
+ pos = tokenPos + 1;
+ return token = 28 /* LessThanToken */;
+ }
+ return token;
+ }
function scanJsxToken() {
startPos = tokenPos = pos;
if (pos >= end) {
@@ -8862,7 +8870,9 @@ var ts;
case 14 /* NoSubstitutionTemplateLiteral */:
return ts.escapeLeadingUnderscores(name.text);
case 149 /* ComputedPropertyName */:
- return isStringOrNumericLiteralLike(name.expression) ? ts.escapeLeadingUnderscores(name.expression.text) : undefined; // TODO: GH#18217 Almost all uses of this assume the result to be defined!
+ if (isStringOrNumericLiteralLike(name.expression))
+ return ts.escapeLeadingUnderscores(name.expression.text);
+ return ts.Debug.fail("Text of property name cannot be read from non-literal-valued ComputedPropertyNames");
default:
return ts.Debug.assertNever(name);
}
@@ -17208,6 +17218,9 @@ var ts;
function reScanTemplateToken() {
return currentToken = scanner.reScanTemplateToken();
}
+ function reScanLessThanToken() {
+ return currentToken = scanner.reScanLessThanToken();
+ }
function scanJsxIdentifier() {
return currentToken = scanner.scanJsxIdentifier();
}
@@ -18219,7 +18232,7 @@ var ts;
function parseTypeReference() {
var node = createNode(164 /* TypeReference */);
node.typeName = parseEntityName(/*allowReservedWords*/ true, ts.Diagnostics.Type_expected);
- if (!scanner.hasPrecedingLineBreak() && token() === 28 /* LessThanToken */) {
+ if (!scanner.hasPrecedingLineBreak() && reScanLessThanToken() === 28 /* LessThanToken */) {
node.typeArguments = parseBracketedList(20 /* TypeArguments */, parseType, 28 /* LessThanToken */, 30 /* GreaterThanToken */);
}
return finishNode(node);
@@ -20241,7 +20254,8 @@ var ts;
function parseCallExpressionRest(expression) {
while (true) {
expression = parseMemberExpressionRest(expression);
- if (token() === 28 /* LessThanToken */) {
+ // handle 'foo<()'
+ if (token() === 28 /* LessThanToken */ || token() === 46 /* LessThanLessThanToken */) {
// See if this is the start of a generic invocation. If so, consume it and
// keep checking for postfix expressions. Otherwise, it's just a '<' that's
// part of an arithmetic expression. Break out so we consume it higher in the
@@ -20278,9 +20292,10 @@ var ts;
return result;
}
function parseTypeArgumentsInExpression() {
- if (!parseOptional(28 /* LessThanToken */)) {
+ if (reScanLessThanToken() !== 28 /* LessThanToken */) {
return undefined;
}
+ nextToken();
var typeArguments = parseDelimitedList(20 /* TypeArguments */, parseType);
if (!parseExpected(30 /* GreaterThanToken */)) {
// If it doesn't have the closing `>` then it's definitely not an type argument list.
@@ -27153,6 +27168,7 @@ var ts;
ContainerFlags[ContainerFlags["IsInterface"] = 64] = "IsInterface";
ContainerFlags[ContainerFlags["IsObjectLiteralOrClassExpressionMethod"] = 128] = "IsObjectLiteralOrClassExpressionMethod";
})(ContainerFlags || (ContainerFlags = {}));
+ var flowNodeCreated = ts.identity;
var binder = createBinder();
function bindSourceFile(file, options) {
ts.performance.mark("beforeBind");
@@ -27541,6 +27557,7 @@ var ts;
blockScopeContainer.locals = undefined;
}
if (containerFlags & 4 /* IsControlFlowContainer */) {
+ var saveFlowNodeCreated = flowNodeCreated;
var saveCurrentFlow = currentFlow;
var saveBreakTarget = currentBreakTarget;
var saveContinueTarget = currentContinueTarget;
@@ -27564,6 +27581,7 @@ var ts;
currentContinueTarget = undefined;
activeLabels = undefined;
hasExplicitReturn = false;
+ flowNodeCreated = ts.identity;
bindChildren(node);
// Reset all reachability check related flags on node (for incremental scenarios)
node.flags &= ~1408 /* ReachabilityAndEmitFlags */;
@@ -27590,6 +27608,7 @@ var ts;
currentReturnTarget = saveReturnTarget;
activeLabels = saveActiveLabels;
hasExplicitReturn = saveHasExplicitReturn;
+ flowNodeCreated = saveFlowNodeCreated;
}
else if (containerFlags & 64 /* IsInterface */) {
seenThisKeyword = false;
@@ -27853,22 +27872,22 @@ var ts;
return antecedent;
}
setFlowNodeReferenced(antecedent);
- return { flags: flags, expression: expression, antecedent: antecedent };
+ return flowNodeCreated({ flags: flags, expression: expression, antecedent: antecedent });
}
function createFlowSwitchClause(antecedent, switchStatement, clauseStart, clauseEnd) {
if (!isNarrowingExpression(switchStatement.expression)) {
return antecedent;
}
setFlowNodeReferenced(antecedent);
- return { flags: 128 /* SwitchClause */, switchStatement: switchStatement, clauseStart: clauseStart, clauseEnd: clauseEnd, antecedent: antecedent };
+ return flowNodeCreated({ flags: 128 /* SwitchClause */, switchStatement: switchStatement, clauseStart: clauseStart, clauseEnd: clauseEnd, antecedent: antecedent });
}
function createFlowAssignment(antecedent, node) {
setFlowNodeReferenced(antecedent);
- return { flags: 16 /* Assignment */, antecedent: antecedent, node: node };
+ return flowNodeCreated({ flags: 16 /* Assignment */, antecedent: antecedent, node: node });
}
function createFlowArrayMutation(antecedent, node) {
setFlowNodeReferenced(antecedent);
- var res = { flags: 256 /* ArrayMutation */, antecedent: antecedent, node: node };
+ var res = flowNodeCreated({ flags: 256 /* ArrayMutation */, antecedent: antecedent, node: node });
return res;
}
function finishFlowLabel(flow) {
@@ -28056,18 +28075,46 @@ var ts;
function bindTryStatement(node) {
var preFinallyLabel = createBranchLabel();
var preTryFlow = currentFlow;
- // TODO: Every statement in try block is potentially an exit point!
+ var tryPriors = [];
+ var oldFlowNodeCreated = flowNodeCreated;
+ // We hook the creation of all flow nodes within the `try` scope and store them so we can add _all_ of them
+ // as possible antecedents of the start of the `catch` or `finally` blocks.
+ // Don't bother intercepting the call if there's no finally or catch block that needs the information
+ if (node.catchClause || node.finallyBlock) {
+ flowNodeCreated = function (node) { return (tryPriors.push(node), node); };
+ }
bind(node.tryBlock);
+ flowNodeCreated = oldFlowNodeCreated;
addAntecedent(preFinallyLabel, currentFlow);
var flowAfterTry = currentFlow;
var flowAfterCatch = unreachableFlow;
if (node.catchClause) {
currentFlow = preTryFlow;
+ if (tryPriors.length) {
+ var preCatchFlow = createBranchLabel();
+ addAntecedent(preCatchFlow, currentFlow);
+ for (var _i = 0, tryPriors_1 = tryPriors; _i < tryPriors_1.length; _i++) {
+ var p = tryPriors_1[_i];
+ addAntecedent(preCatchFlow, p);
+ }
+ currentFlow = finishFlowLabel(preCatchFlow);
+ }
bind(node.catchClause);
addAntecedent(preFinallyLabel, currentFlow);
flowAfterCatch = currentFlow;
}
if (node.finallyBlock) {
+ // We add the nodes within the `try` block to the `finally`'s antecedents if there's no catch block
+ // (If there is a `catch` block, it will have all these antecedents instead, and the `finally` will
+ // have the end of the `try` block and the end of the `catch` block)
+ if (!node.catchClause) {
+ if (tryPriors.length) {
+ for (var _a = 0, tryPriors_2 = tryPriors; _a < tryPriors_2.length; _a++) {
+ var p = tryPriors_2[_a];
+ addAntecedent(preFinallyLabel, p);
+ }
+ }
+ }
// in finally flow is combined from pre-try/flow from try/flow from catch
// pre-flow is necessary to make sure that finally is reachable even if finally flows in both try and finally blocks are unreachable
// also for finally blocks we inject two extra edges into the flow graph.
@@ -28112,7 +28159,7 @@ var ts;
}
}
if (!(currentFlow.flags & 1 /* Unreachable */)) {
- var afterFinallyFlow = { flags: 4096 /* AfterFinally */, antecedent: currentFlow };
+ var afterFinallyFlow = flowNodeCreated({ flags: 4096 /* AfterFinally */, antecedent: currentFlow });
preFinallyFlow.lock = afterFinallyFlow;
currentFlow = afterFinallyFlow;
}
@@ -35638,16 +35685,17 @@ var ts;
var objectFlags = 128 /* ObjectLiteral */;
ts.forEach(pattern.elements, function (e) {
var name = e.propertyName || e.name;
- if (isComputedNonLiteralName(name)) {
- // do not include computed properties in the implied type
- objectFlags |= 512 /* ObjectLiteralPatternWithComputedProperties */;
- return;
- }
if (e.dotDotDotToken) {
stringIndexInfo = createIndexInfo(anyType, /*isReadonly*/ false);
return;
}
- var text = ts.getTextOfPropertyName(name);
+ var exprType = getLiteralTypeFromPropertyName(name);
+ if (!isTypeUsableAsPropertyName(exprType)) {
+ // do not include computed properties in the implied type
+ objectFlags |= 512 /* ObjectLiteralPatternWithComputedProperties */;
+ return;
+ }
+ var text = getPropertyNameFromType(exprType);
var flags = 4 /* Property */ | (e.initializer ? 16777216 /* Optional */ : 0);
var symbol = createSymbol(flags, text);
symbol.type = getTypeFromBindingElement(e, includePatternInType, reportErrors);
@@ -36689,9 +36737,9 @@ var ts;
return type;
}
/**
- * Indicates whether a type can be used as a late-bound name.
+ * Indicates whether a type can be used as a property name.
*/
- function isTypeUsableAsLateBoundName(type) {
+ function isTypeUsableAsPropertyName(type) {
return !!(type.flags & 8576 /* StringOrNumberLiteralOrUnique */);
}
/**
@@ -36705,7 +36753,7 @@ var ts;
function isLateBindableName(node) {
return ts.isComputedPropertyName(node)
&& ts.isEntityNameExpression(node.expression)
- && isTypeUsableAsLateBoundName(checkComputedPropertyName(node));
+ && isTypeUsableAsPropertyName(checkComputedPropertyName(node));
}
function isLateBoundName(name) {
return name.charCodeAt(0) === 95 /* _ */ &&
@@ -36732,11 +36780,11 @@ var ts;
return ts.isDynamicName(node) && !isLateBindableName(node);
}
/**
- * Gets the symbolic name for a late-bound member from its type.
+ * Gets the symbolic name for a member from its type.
*/
- function getLateBoundNameFromType(type) {
+ function getPropertyNameFromType(type) {
if (type.flags & 8192 /* UniqueESSymbol */) {
- return "__@" + type.symbol.escapedName + "@" + getSymbolId(type.symbol);
+ return type.escapedName;
}
if (type.flags & (128 /* StringLiteral */ | 256 /* NumberLiteral */)) {
return ts.escapeLeadingUnderscores("" + type.value);
@@ -36800,8 +36848,8 @@ var ts;
// fall back to the early-bound name of this member.
links.resolvedSymbol = decl.symbol;
var type = checkComputedPropertyName(decl.name);
- if (isTypeUsableAsLateBoundName(type)) {
- var memberName = getLateBoundNameFromType(type);
+ if (isTypeUsableAsPropertyName(type)) {
+ var memberName = getPropertyNameFromType(type);
var symbolFlags = decl.symbol.flags;
// Get or add a late-bound symbol for the member. This allows us to merge late-bound accessor declarations.
var lateSymbol = lateSymbols.get(memberName);
@@ -36815,9 +36863,9 @@ var ts;
// If we have an existing early-bound member, combine its declarations so that we can
// report an error at each declaration.
var declarations = earlySymbol ? ts.concatenate(earlySymbol.declarations, lateSymbol.declarations) : lateSymbol.declarations;
- var name_3 = ts.declarationNameToString(decl.name);
- ts.forEach(declarations, function (declaration) { return error(ts.getNameOfDeclaration(declaration) || declaration, ts.Diagnostics.Duplicate_declaration_0, name_3); });
- error(decl.name || decl, ts.Diagnostics.Duplicate_declaration_0, name_3);
+ var name_3 = !(type.flags & 8192 /* UniqueESSymbol */) && ts.unescapeLeadingUnderscores(memberName) || ts.declarationNameToString(decl.name);
+ ts.forEach(declarations, function (declaration) { return error(ts.getNameOfDeclaration(declaration) || declaration, ts.Diagnostics.Property_0_was_also_declared_here, name_3); });
+ error(decl.name || decl, ts.Diagnostics.Duplicate_property_0, name_3);
lateSymbol = createSymbol(0 /* None */, memberName, 2048 /* Late */);
}
lateSymbol.nameType = type;
@@ -37409,8 +37457,8 @@ var ts;
var propType = instantiateType(templateType, templateMapper);
// If the current iteration type constituent is a string literal type, create a property.
// Otherwise, for type string create a string index signature.
- if (t.flags & 8576 /* StringOrNumberLiteralOrUnique */) {
- var propName = getLateBoundNameFromType(t);
+ if (isTypeUsableAsPropertyName(t)) {
+ var propName = getPropertyNameFromType(t);
var modifiersProp = getPropertyOfType(modifiersType, propName);
var isOptional = !!(templateModifiers & 4 /* IncludeOptional */ ||
!(templateModifiers & 8 /* ExcludeOptional */) && modifiersProp && modifiersProp.flags & 16777216 /* Optional */);
@@ -37580,7 +37628,8 @@ var ts;
function isTypeInvalidDueToUnionDiscriminant(contextualType, obj) {
var list = obj.properties;
return list.some(function (property) {
- var name = property.name && ts.getTextOfPropertyName(property.name);
+ var nameType = property.name && getLiteralTypeFromPropertyName(property.name);
+ var name = nameType && isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined;
var expected = name === undefined ? undefined : getTypeOfPropertyOfType(contextualType, name);
return !!expected && isLiteralType(expected) && !isTypeIdenticalTo(getTypeOfNode(property), expected);
});
@@ -37950,6 +37999,10 @@ var ts;
result.containingType = containingType;
if (!hasNonUniformValueDeclaration && firstValueDeclaration) {
result.valueDeclaration = firstValueDeclaration;
+ // Inherit information about parent type.
+ if (firstValueDeclaration.symbol.parent) {
+ result.parent = firstValueDeclaration.symbol.parent;
+ }
}
result.declarations = declarations;
result.nameType = nameType;
@@ -38808,21 +38861,16 @@ var ts;
* the type of this reference is just the type of the value we resolved to.
*/
function getJSDocTypeReference(node, symbol, typeArguments) {
- if (!pushTypeResolution(symbol, 6 /* JSDocTypeReference */)) {
- return errorType;
- }
- var assignedType = getAssignedClassType(symbol);
- var valueType = getTypeOfSymbol(symbol);
- var referenceType = valueType.symbol && valueType.symbol !== symbol && !isInferredClassType(valueType) && getTypeReferenceTypeWorker(node, valueType.symbol, typeArguments);
- if (!popTypeResolution()) {
- getSymbolLinks(symbol).resolvedJSDocType = errorType;
- error(node, ts.Diagnostics.JSDoc_type_0_circularly_references_itself, symbolToString(symbol));
- return errorType;
- }
- if (referenceType || assignedType) {
- // TODO: GH#18217 (should the `|| assignedType` be at a lower precedence?)
- var type = (referenceType && assignedType ? getIntersectionType([assignedType, referenceType]) : referenceType || assignedType);
- return getSymbolLinks(symbol).resolvedJSDocType = type;
+ // In the case of an assignment of a function expression (binary expressions, variable declarations, etc.), we will get the
+ // correct instance type for the symbol on the LHS by finding the type for RHS. For example if we want to get the type of the symbol `foo`:
+ // var foo = function() {}
+ // We will find the static type of the assigned anonymous function.
+ var staticType = getTypeOfSymbol(symbol);
+ var instanceType = staticType.symbol &&
+ staticType.symbol !== symbol && // Make sure this is an assignment like expression by checking that symbol -> type -> symbol doesn't roundtrips.
+ getTypeReferenceTypeWorker(node, staticType.symbol, typeArguments); // Get the instance type of the RHS symbol.
+ if (instanceType) {
+ return getSymbolLinks(symbol).resolvedJSDocType = instanceType;
}
}
function getTypeReferenceTypeWorker(node, symbol, typeArguments) {
@@ -38840,8 +38888,11 @@ var ts;
}
if (symbol.flags & 16 /* Function */ &&
isJSDocTypeReference(node) &&
- (symbol.members || ts.getJSDocClassTag(symbol.valueDeclaration))) {
- return getInferredClassType(symbol);
+ isJSConstructor(symbol.valueDeclaration)) {
+ var resolved = resolveStructuredTypeMembers(getTypeOfSymbol(symbol));
+ if (resolved.callSignatures.length === 1) {
+ return getReturnTypeOfSignature(resolved.callSignatures[0]);
+ }
}
}
function getSubstitutionType(typeVariable, substitute) {
@@ -39738,8 +39789,8 @@ var ts;
}
function getPropertyTypeForIndexType(objectType, indexType, accessNode, cacheSymbol, missingType) {
var accessExpression = accessNode && accessNode.kind === 190 /* ElementAccessExpression */ ? accessNode : undefined;
- var propName = isTypeUsableAsLateBoundName(indexType) ?
- getLateBoundNameFromType(indexType) :
+ var propName = isTypeUsableAsPropertyName(indexType) ?
+ getPropertyNameFromType(indexType) :
accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ?
ts.getPropertyNameForKnownSymbolName(ts.idText(accessExpression.argumentExpression.name)) :
accessNode && ts.isPropertyName(accessNode) ?
@@ -40383,6 +40434,7 @@ var ts;
function createUniqueESSymbolType(symbol) {
var type = createType(8192 /* UniqueESSymbol */);
type.symbol = symbol;
+ type.escapedName = "__@" + type.symbol.escapedName + "@" + getSymbolId(type.symbol);
return type;
}
function getESSymbolLikeTypeForNode(node) {
@@ -40580,7 +40632,9 @@ var ts;
return type.flags & 262144 /* TypeParameter */ ? wildcardType : type;
}
function getRestrictiveTypeParameter(tp) {
- return !tp.constraint ? tp : tp.restrictiveInstantiation || (tp.restrictiveInstantiation = createTypeParameter(tp.symbol));
+ return tp.constraint === unknownType ? tp : tp.restrictiveInstantiation || (tp.restrictiveInstantiation = createTypeParameter(tp.symbol),
+ tp.restrictiveInstantiation.constraint = unknownType,
+ tp.restrictiveInstantiation);
}
function restrictiveMapper(type) {
return type.flags & 262144 /* TypeParameter */ ? getRestrictiveTypeParameter(type) : type;
@@ -41195,7 +41249,7 @@ var ts;
}
if (resultObj.error) {
var reportedDiag = resultObj.error;
- var propertyName = isTypeUsableAsLateBoundName(nameType) ? getLateBoundNameFromType(nameType) : undefined;
+ var propertyName = isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined;
var targetProp = propertyName !== undefined ? getPropertyOfType(target, propertyName) : undefined;
var issuedElaboration = false;
if (!targetProp) {
@@ -42551,7 +42605,7 @@ var ts;
}
else {
// An empty object type is related to any mapped type that includes a '?' modifier.
- if (isPartialMappedType(target) && isEmptyObjectType(source)) {
+ if (relation !== subtypeRelation && isPartialMappedType(target) && isEmptyObjectType(source)) {
return -1 /* True */;
}
if (isGenericMappedType(target)) {
@@ -44355,7 +44409,11 @@ var ts;
priority |= 4 /* MappedTypeConstraint */;
inferFromTypes(getIndexType(source), constraintType);
priority = savePriority;
- inferFromTypes(getUnionType(ts.map(getPropertiesOfType(source), getTypeOfSymbol)), getTemplateTypeFromMappedType(target));
+ var valueTypes = ts.compact([
+ getIndexTypeOfType(source, 0 /* String */),
+ getIndexTypeOfType(source, 1 /* Number */)
+ ].concat(ts.map(getPropertiesOfType(source), getTypeOfSymbol)));
+ inferFromTypes(getUnionType(valueTypes), getTemplateTypeFromMappedType(target));
return true;
}
return false;
@@ -44912,7 +44970,10 @@ var ts;
return type;
}
function getTypeOfDestructuredProperty(type, name) {
- var text = ts.getTextOfPropertyName(name);
+ var nameType = getLiteralTypeFromPropertyName(name);
+ if (!isTypeUsableAsPropertyName(nameType))
+ return errorType;
+ var text = getPropertyNameFromType(nameType);
return getConstraintForLocation(getTypeOfPropertyOfType(type, text), name) ||
isNumericLiteralName(text) && getIndexTypeOfType(type, 1 /* Number */) ||
getIndexTypeOfType(type, 0 /* String */) ||
@@ -45470,9 +45531,6 @@ var ts;
}
function getTypeAtSwitchClause(flow) {
var expr = flow.switchStatement.expression;
- if (containsMatchingReferenceDiscriminant(reference, expr)) {
- return declaredType;
- }
var flowType = getTypeAtFlowNode(flow.antecedent);
var type = getTypeFromFlowType(flowType);
if (isMatchingReference(reference, expr)) {
@@ -45484,6 +45542,9 @@ var ts;
else if (expr.kind === 199 /* TypeOfExpression */ && isMatchingReference(reference, expr.expression)) {
type = narrowBySwitchOnTypeOf(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd);
}
+ else if (containsMatchingReferenceDiscriminant(reference, expr)) {
+ type = declaredType;
+ }
return createFlowType(type, isIncomplete(flowType));
}
function getTypeAtFlowBranchLabel(flow) {
@@ -46476,7 +46537,7 @@ var ts;
else if (isInJS &&
(container.kind === 196 /* FunctionExpression */ || container.kind === 239 /* FunctionDeclaration */) &&
ts.getJSDocClassTag(container)) {
- var classType = getJSClassType(container.symbol);
+ var classType = getJSClassType(getMergedSymbol(container.symbol));
if (classType) {
return getFlowTypeOfReference(node, classType);
}
@@ -46871,9 +46932,10 @@ var ts;
var parentDeclaration = declaration.parent.parent;
var name = declaration.propertyName || declaration.name;
var parentType = getContextualTypeForVariableLikeDeclaration(parentDeclaration);
- if (parentType && !ts.isBindingPattern(name)) {
- var text = ts.getTextOfPropertyName(name);
- if (text !== undefined) {
+ if (parentType && !ts.isBindingPattern(name) && !isComputedNonLiteralName(name)) {
+ var nameType = getLiteralTypeFromPropertyName(name);
+ if (isTypeUsableAsPropertyName(nameType)) {
+ var text = getPropertyNameFromType(nameType);
return getTypeOfPropertyOfType(parentType, text);
}
}
@@ -47747,10 +47809,9 @@ var ts;
}
}
typeFlags |= type.flags;
- var nameType = computedNameType && computedNameType.flags & 8576 /* StringOrNumberLiteralOrUnique */ ?
- computedNameType : undefined;
+ var nameType = computedNameType && isTypeUsableAsPropertyName(computedNameType) ? computedNameType : undefined;
var prop = nameType ?
- createSymbol(4 /* Property */ | member.flags, getLateBoundNameFromType(nameType), 2048 /* Late */) :
+ createSymbol(4 /* Property */ | member.flags, getPropertyNameFromType(nameType), 2048 /* Late */) :
createSymbol(4 /* Property */ | member.flags, member.escapedName);
if (nameType) {
prop.nameType = nameType;
@@ -48008,6 +48069,10 @@ var ts;
childrenPropSymbol.type = childrenTypes.length === 1 ?
childrenTypes[0] :
(getArrayLiteralTupleTypeIfApplicable(childrenTypes, childrenContextualType, /*hasRestElement*/ false) || createArrayType(getUnionType(childrenTypes)));
+ // Fake up a property declaration for the children
+ childrenPropSymbol.valueDeclaration = ts.createPropertySignature(/*modifiers*/ undefined, ts.unescapeLeadingUnderscores(jsxChildrenPropertyName), /*questionToken*/ undefined, /*type*/ undefined, /*initializer*/ undefined);
+ childrenPropSymbol.valueDeclaration.parent = attributes;
+ childrenPropSymbol.valueDeclaration.symbol = childrenPropSymbol;
var childPropMap = ts.createSymbolTable();
childPropMap.set(jsxChildrenPropertyName, childrenPropSymbol);
spread = getSpreadType(spread, createAnonymousType(attributes.symbol, childPropMap, ts.emptyArray, ts.emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined), attributes.symbol, typeFlags, objectFlags);
@@ -49687,6 +49752,12 @@ var ts;
if (inferenceContext) {
var typeArgumentTypes = inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext);
checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration));
+ // If the original signature has a generic rest type, instantiation may produce a
+ // signature with different arity and we need to perform another arity check.
+ if (getNonArrayRestType(candidate) && !hasCorrectArity(node, args, checkCandidate, signatureHelpTrailingComma)) {
+ candidateForArgumentArityError = checkCandidate;
+ continue;
+ }
}
if (!checkApplicableSignature(node, args, checkCandidate, relation, excludeArgument, /*reportErrors*/ false)) {
// Give preference to error candidates that have no rest parameters (as they are more specific)
@@ -50238,7 +50309,7 @@ var ts;
return true;
// If the symbol of the node has members, treat it like a constructor.
var symbol = getSymbolOfNode(func);
- return !!symbol && symbol.members !== undefined;
+ return !!symbol && (symbol.members !== undefined || symbol.exports !== undefined && symbol.exports.get("prototype") !== undefined);
}
return false;
}
@@ -50255,10 +50326,6 @@ var ts;
inferred = getInferredClassType(symbol);
}
var assigned = getAssignedClassType(symbol);
- var valueType = getTypeOfSymbol(symbol);
- if (valueType.symbol && !isInferredClassType(valueType) && isJSConstructor(valueType.symbol.valueDeclaration)) {
- inferred = getInferredClassType(valueType.symbol);
- }
return assigned && inferred ?
getIntersectionType([inferred, assigned]) :
assigned || inferred;
@@ -50293,11 +50360,6 @@ var ts;
}
return links.inferredClassType;
}
- function isInferredClassType(type) {
- return type.symbol
- && ts.getObjectFlags(type) & 16 /* Anonymous */
- && getSymbolLinks(type.symbol).inferredClassType === type;
- }
/**
* Syntactically and semantically checks a call or new expression.
* @param node The call/new expression to be checked.
@@ -50316,20 +50378,9 @@ var ts;
declaration.kind !== 157 /* Constructor */ &&
declaration.kind !== 161 /* ConstructSignature */ &&
declaration.kind !== 166 /* ConstructorType */ &&
- !ts.isJSDocConstructSignature(declaration)) {
- // When resolved signature is a call signature (and not a construct signature) the result type is any, unless
- // the declaring function had members created through 'x.prototype.y = expr' or 'this.y = expr' psuedodeclarations
- // in a JS file
- // Note:JS inferred classes might come from a variable declaration instead of a function declaration.
- // In this case, using getResolvedSymbol directly is required to avoid losing the members from the declaration.
- var funcSymbol = checkExpression(node.expression).symbol;
- if (!funcSymbol && node.expression.kind === 72 /* Identifier */) {
- funcSymbol = getResolvedSymbol(node.expression);
- }
- var type = funcSymbol && getJSClassType(funcSymbol);
- if (type) {
- return signature.target ? instantiateType(type, signature.mapper) : type;
- }
+ !ts.isJSDocConstructSignature(declaration) &&
+ !isJSConstructor(declaration)) {
+ // When resolved signature is a call signature (and not a construct signature) the result type is any
if (noImplicitAny) {
error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type);
}
@@ -51384,7 +51435,7 @@ var ts;
if (!(isTypeComparableTo(leftType, stringType) || isTypeAssignableToKind(leftType, 296 /* NumberLike */ | 12288 /* ESSymbolLike */))) {
error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol);
}
- if (!isTypeAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */)) {
+ if (!allTypesAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */)) {
error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
}
return booleanType;
@@ -51405,15 +51456,15 @@ var ts;
if (rightIsThis === void 0) { rightIsThis = false; }
if (property.kind === 275 /* PropertyAssignment */ || property.kind === 276 /* ShorthandPropertyAssignment */) {
var name = property.name;
- var text = ts.getTextOfPropertyName(name);
- if (text) {
+ var exprType = getLiteralTypeFromPropertyName(name);
+ if (isTypeUsableAsPropertyName(exprType)) {
+ var text = getPropertyNameFromType(exprType);
var prop = getPropertyOfType(objectLiteralType, text);
if (prop) {
markPropertyAsReferenced(prop, property, rightIsThis);
checkPropertyAccessibility(property, /*isSuper*/ false, objectLiteralType, prop);
}
}
- var exprType = getLiteralTypeFromPropertyName(name);
var elementType = getIndexedAccessType(objectLiteralType, exprType, name);
var type = getFlowTypeOfDestructuring(property, elementType);
return checkDestructuringAssignment(property.kind === 276 /* ShorthandPropertyAssignment */ ? property : property.initializer, type);
@@ -54403,10 +54454,11 @@ var ts;
var parent = node.parent.parent;
var parentType = getTypeForBindingElementParent(parent);
var name = node.propertyName || node.name;
- if (!ts.isBindingPattern(name)) {
- var nameText = ts.getTextOfPropertyName(name);
- if (nameText) {
- var property = getPropertyOfType(parentType, nameText); // TODO: GH#18217
+ if (!ts.isBindingPattern(name) && parentType) {
+ var exprType = getLiteralTypeFromPropertyName(name);
+ if (isTypeUsableAsPropertyName(exprType)) {
+ var nameText = getPropertyNameFromType(exprType);
+ var property = getPropertyOfType(parentType, nameText);
if (property) {
markPropertyAsReferenced(property, /*nodeForCheckWriteOnly*/ undefined, /*isThisAccess*/ false); // A destructuring is never a write-only reference.
checkPropertyAccessibility(parent, !!parent.initializer && parent.initializer.kind === 98 /* SuperKeyword */, parentType, property);
@@ -54763,7 +54815,7 @@ var ts;
? downlevelIteration
? ts.Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator
: isIterable
- ? ts.Diagnostics.Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators
+ ? ts.Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators
: ts.Diagnostics.Type_0_is_not_an_array_type
: downlevelIteration
? ts.Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator
@@ -59405,6 +59457,7 @@ var ts;
if (nodeArguments.length !== 1) {
return grammarErrorOnNode(node, ts.Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument);
}
+ checkGrammarForDisallowedTrailingComma(nodeArguments);
// see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import.
// parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import.
if (ts.isSpreadElement(nodeArguments[0])) {
@@ -61837,22 +61890,62 @@ var ts;
return node;
}
ts.createBundle = createBundle;
- function createUnparsedSourceFile(text, mapPath, map) {
+ function createUnparsedSourceFile(textOrInputFiles, mapPathOrType, map) {
var node = ts.createNode(281 /* UnparsedSource */);
- node.text = text;
- node.sourceMapPath = mapPath;
- node.sourceMapText = map;
+ if (!ts.isString(textOrInputFiles)) {
+ ts.Debug.assert(mapPathOrType === "js" || mapPathOrType === "dts");
+ node.fileName = mapPathOrType === "js" ? textOrInputFiles.javascriptPath : textOrInputFiles.declarationPath;
+ node.sourceMapPath = mapPathOrType === "js" ? textOrInputFiles.javascriptMapPath : textOrInputFiles.declarationMapPath;
+ Object.defineProperties(node, {
+ text: { get: function () { return mapPathOrType === "js" ? textOrInputFiles.javascriptText : textOrInputFiles.declarationText; } },
+ sourceMapText: { get: function () { return mapPathOrType === "js" ? textOrInputFiles.javascriptMapText : textOrInputFiles.declarationMapText; } },
+ });
+ }
+ else {
+ node.text = textOrInputFiles;
+ node.sourceMapPath = mapPathOrType;
+ node.sourceMapText = map;
+ }
return node;
}
ts.createUnparsedSourceFile = createUnparsedSourceFile;
- function createInputFiles(javascript, declaration, javascriptMapPath, javascriptMapText, declarationMapPath, declarationMapText) {
+ function createInputFiles(javascriptTextOrReadFileText, declarationTextOrJavascriptPath, javascriptMapPath, javascriptMapTextOrDeclarationPath, declarationMapPath, declarationMapText) {
var node = ts.createNode(282 /* InputFiles */);
- node.javascriptText = javascript;
- node.javascriptMapPath = javascriptMapPath;
- node.javascriptMapText = javascriptMapText;
- node.declarationText = declaration;
- node.declarationMapPath = declarationMapPath;
- node.declarationMapText = declarationMapText;
+ if (!ts.isString(javascriptTextOrReadFileText)) {
+ var cache_1 = ts.createMap();
+ var textGetter_1 = function (path) {
+ if (path === undefined)
+ return undefined;
+ var value = cache_1.get(path);
+ if (value === undefined) {
+ value = javascriptTextOrReadFileText(path);
+ cache_1.set(path, value !== undefined ? value : false);
+ }
+ return value !== false ? value : undefined;
+ };
+ var definedTextGetter_1 = function (path) {
+ var result = textGetter_1(path);
+ return result !== undefined ? result : "/* Input file " + path + " was missing */\r\n";
+ };
+ node.javascriptPath = declarationTextOrJavascriptPath;
+ node.javascriptMapPath = javascriptMapPath;
+ node.declarationPath = ts.Debug.assertDefined(javascriptMapTextOrDeclarationPath);
+ node.declarationMapPath = declarationMapPath;
+ Object.defineProperties(node, {
+ javascriptText: { get: function () { return definedTextGetter_1(declarationTextOrJavascriptPath); } },
+ javascriptMapText: { get: function () { return textGetter_1(javascriptMapPath); } },
+ declarationText: { get: function () { return definedTextGetter_1(ts.Debug.assertDefined(javascriptMapTextOrDeclarationPath)); } },
+ declarationMapText: { get: function () { return textGetter_1(declarationMapPath); } } // TODO:: if there is inline sourceMap in dtsFile, use that
+ });
+ }
+ else {
+ node.javascriptText = javascriptTextOrReadFileText;
+ node.javascriptMapPath = javascriptMapPath;
+ node.javascriptMapText = javascriptMapTextOrDeclarationPath;
+ node.declarationText = declarationTextOrJavascriptPath;
+ node.declarationMapPath = declarationMapPath;
+ node.declarationMapText = declarationMapText;
+ }
return node;
}
ts.createInputFiles = createInputFiles;
@@ -66203,7 +66296,7 @@ var ts;
function transformBundle(node) {
return ts.createBundle(node.sourceFiles.map(transformSourceFile), ts.mapDefined(node.prepends, function (prepend) {
if (prepend.kind === 282 /* InputFiles */) {
- return ts.createUnparsedSourceFile(prepend.javascriptText, prepend.javascriptMapPath, prepend.javascriptMapText);
+ return ts.createUnparsedSourceFile(prepend, "js");
}
return prepend;
}));
@@ -80436,7 +80529,7 @@ var ts;
return ts.updateSourceFileNode(sourceFile, transformAndReplaceLatePaintedStatements(updated), /*isDeclarationFile*/ true, /*referencedFiles*/ [], /*typeReferences*/ [], /*hasNoDefaultLib*/ false, /*libReferences*/ []);
}), ts.mapDefined(node.prepends, function (prepend) {
if (prepend.kind === 282 /* InputFiles */) {
- return ts.createUnparsedSourceFile(prepend.declarationText, prepend.declarationMapPath, prepend.declarationMapText);
+ return ts.createUnparsedSourceFile(prepend, "dts");
}
}));
bundle.syntheticFileReferences = [];
@@ -81797,16 +81890,21 @@ var ts;
}
ts.forEachEmittedFile = forEachEmittedFile;
/*@internal*/
+ function getOutputPathsForBundle(options, forceDtsPaths) {
+ var outPath = options.outFile || options.out;
+ var jsFilePath = options.emitDeclarationOnly ? undefined : outPath;
+ var sourceMapFilePath = jsFilePath && getSourceMapFilePath(jsFilePath, options);
+ var declarationFilePath = (forceDtsPaths || ts.getEmitDeclarations(options)) ? ts.removeFileExtension(outPath) + ".d.ts" /* Dts */ : undefined;
+ var declarationMapPath = declarationFilePath && ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
+ var bundleInfoPath = options.references && jsFilePath ? (ts.removeFileExtension(jsFilePath) + infoExtension) : undefined;
+ return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: bundleInfoPath };
+ }
+ ts.getOutputPathsForBundle = getOutputPathsForBundle;
+ /*@internal*/
function getOutputPathsFor(sourceFile, host, forceDtsPaths) {
var options = host.getCompilerOptions();
if (sourceFile.kind === 280 /* Bundle */) {
- var outPath = options.outFile || options.out;
- var jsFilePath = options.emitDeclarationOnly ? undefined : outPath;
- var sourceMapFilePath = jsFilePath && getSourceMapFilePath(jsFilePath, options);
- var declarationFilePath = (forceDtsPaths || ts.getEmitDeclarations(options)) ? ts.removeFileExtension(outPath) + ".d.ts" /* Dts */ : undefined;
- var declarationMapPath = declarationFilePath && ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
- var bundleInfoPath = options.references && jsFilePath ? (ts.removeFileExtension(jsFilePath) + infoExtension) : undefined;
- return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: bundleInfoPath };
+ return getOutputPathsForBundle(options, forceDtsPaths);
}
else {
var ownOutputFilePath = ts.getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options));
@@ -85601,10 +85699,10 @@ var ts;
}
}
/**
- * Skips trivia such as comments and white-space that can optionally overriden by the source map source
+ * Skips trivia such as comments and white-space that can be optionally overridden by the source-map source
*/
function skipSourceTrivia(source, pos) {
- return source.skipTrivia ? source.skipTrivia(pos) : ts.skipTrivia(sourceMapSource.text, pos);
+ return source.skipTrivia ? source.skipTrivia(pos) : ts.skipTrivia(source.text, pos);
}
/**
* Emits a mapping.
@@ -87275,14 +87373,12 @@ var ts;
// Upstream project didn't have outFile set -- skip (error will have been issued earlier)
if (!out)
continue;
- var dtsFilename = ts.changeExtension(out, ".d.ts");
- var js = host.readFile(out) || "/* Input file " + out + " was missing */\r\n";
- var jsMapPath = out + ".map"; // TODO: try to read sourceMappingUrl comment from the file
- var jsMap = host.readFile(jsMapPath);
- var dts = host.readFile(dtsFilename) || "/* Input file " + dtsFilename + " was missing */\r\n";
- var dtsMapPath = dtsFilename + ".map";
- var dtsMap = host.readFile(dtsMapPath);
- var node = ts.createInputFiles(js, dts, jsMap && jsMapPath, jsMap, dtsMap && dtsMapPath, dtsMap);
+ var _a = ts.getOutputPathsForBundle(resolvedRefOpts.options, /*forceDtsPaths*/ true), jsFilePath = _a.jsFilePath, sourceMapFilePath = _a.sourceMapFilePath, declarationFilePath = _a.declarationFilePath, declarationMapPath = _a.declarationMapPath;
+ var node = ts.createInputFiles(function (fileName) {
+ var path = toPath(fileName);
+ var sourceFile = getSourceFileByPath(path);
+ return sourceFile ? sourceFile.text : filesByName.has(path) ? undefined : host.readFile(path);
+ }, jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath);
nodes.push(node);
}
}
@@ -99672,6 +99768,11 @@ var ts;
}
return ts.createTextSpanFromBounds(start, end);
}
+ function getTextSpanOfEntry(entry) {
+ return entry.kind === 0 /* Span */ ? entry.textSpan :
+ getTextSpan(entry.node, entry.node.getSourceFile());
+ }
+ FindAllReferences.getTextSpanOfEntry = getTextSpanOfEntry;
/** A node is considered a writeAccess iff it is a name of a declaration or a target of an assignment */
function isWriteAccessForReference(node) {
var decl = ts.getDeclarationFromName(node);
@@ -99765,24 +99866,100 @@ var ts;
if (symbol.escapedName === "export=" /* ExportEquals */) {
return getReferencedSymbolsForModule(program, symbol.parent, /*excludeImportTypeOfExportEquals*/ false, sourceFiles, sourceFilesSet);
}
- var moduleReferences = ts.emptyArray;
- var moduleSourceFile = isModuleSymbol(symbol);
- var referencedNode = node;
- if (moduleSourceFile) {
- var exportEquals = symbol.exports.get("export=" /* ExportEquals */);
- // If !!exportEquals, we're about to add references to `import("mod")` anyway, so don't double-count them.
- moduleReferences = getReferencedSymbolsForModule(program, symbol, !!exportEquals, sourceFiles, sourceFilesSet);
- if (!exportEquals || !sourceFilesSet.has(moduleSourceFile.fileName))
- return moduleReferences;
- // Continue to get references to 'export ='.
- symbol = ts.skipAlias(exportEquals, checker);
- referencedNode = undefined;
- }
- return ts.concatenate(moduleReferences, getReferencedSymbolsForSymbol(symbol, referencedNode, sourceFiles, sourceFilesSet, checker, cancellationToken, options));
+ var moduleReferences = getReferencedSymbolsForModuleIfDeclaredBySourceFile(symbol, program, sourceFiles, cancellationToken, options, sourceFilesSet);
+ if (moduleReferences && !(symbol.flags & 33554432 /* Transient */)) {
+ return moduleReferences;
+ }
+ var aliasedSymbol = getMergedAliasedSymbolOfNamespaceExportDeclaration(node, symbol, checker);
+ var moduleReferencesOfExportTarget = aliasedSymbol &&
+ getReferencedSymbolsForModuleIfDeclaredBySourceFile(aliasedSymbol, program, sourceFiles, cancellationToken, options, sourceFilesSet);
+ var references = getReferencedSymbolsForSymbol(symbol, node, sourceFiles, sourceFilesSet, checker, cancellationToken, options);
+ return mergeReferences(program, moduleReferences, references, moduleReferencesOfExportTarget);
}
Core.getReferencedSymbolsForNode = getReferencedSymbolsForNode;
- function isModuleSymbol(symbol) {
- return symbol.flags & 1536 /* Module */ ? ts.find(symbol.declarations, ts.isSourceFile) : undefined;
+ function getMergedAliasedSymbolOfNamespaceExportDeclaration(node, symbol, checker) {
+ if (node.parent && ts.isNamespaceExportDeclaration(node.parent)) {
+ var aliasedSymbol = checker.getAliasedSymbol(symbol);
+ var targetSymbol = checker.getMergedSymbol(aliasedSymbol);
+ if (aliasedSymbol !== targetSymbol) {
+ return targetSymbol;
+ }
+ }
+ return undefined;
+ }
+ function getReferencedSymbolsForModuleIfDeclaredBySourceFile(symbol, program, sourceFiles, cancellationToken, options, sourceFilesSet) {
+ var moduleSourceFile = symbol.flags & 1536 /* Module */ ? ts.find(symbol.declarations, ts.isSourceFile) : undefined;
+ if (!moduleSourceFile)
+ return undefined;
+ var exportEquals = symbol.exports.get("export=" /* ExportEquals */);
+ // If !!exportEquals, we're about to add references to `import("mod")` anyway, so don't double-count them.
+ var moduleReferences = getReferencedSymbolsForModule(program, symbol, !!exportEquals, sourceFiles, sourceFilesSet);
+ if (!exportEquals || !sourceFilesSet.has(moduleSourceFile.fileName))
+ return moduleReferences;
+ // Continue to get references to 'export ='.
+ var checker = program.getTypeChecker();
+ symbol = ts.skipAlias(exportEquals, checker);
+ return mergeReferences(program, moduleReferences, getReferencedSymbolsForSymbol(symbol, /*node*/ undefined, sourceFiles, sourceFilesSet, checker, cancellationToken, options));
+ }
+ /**
+ * Merges the references by sorting them (by file index in sourceFiles and their location in it) that point to same definition symbol
+ */
+ function mergeReferences(program) {
+ var referencesToMerge = [];
+ for (var _i = 1; _i < arguments.length; _i++) {
+ referencesToMerge[_i - 1] = arguments[_i];
+ }
+ var result;
+ for (var _a = 0, referencesToMerge_1 = referencesToMerge; _a < referencesToMerge_1.length; _a++) {
+ var references = referencesToMerge_1[_a];
+ if (!references || !references.length)
+ continue;
+ if (!result) {
+ result = references;
+ continue;
+ }
+ var _loop_3 = function (entry) {
+ if (!entry.definition || entry.definition.type !== 0 /* Symbol */) {
+ result.push(entry);
+ return "continue";
+ }
+ var symbol = entry.definition.symbol;
+ var refIndex = ts.findIndex(result, function (ref) { return !!ref.definition &&
+ ref.definition.type === 0 /* Symbol */ &&
+ ref.definition.symbol === symbol; });
+ if (refIndex === -1) {
+ result.push(entry);
+ return "continue";
+ }
+ var reference = result[refIndex];
+ result[refIndex] = {
+ definition: reference.definition,
+ references: reference.references.concat(entry.references).sort(function (entry1, entry2) {
+ var entry1File = getSourceFileIndexOfEntry(program, entry1);
+ var entry2File = getSourceFileIndexOfEntry(program, entry2);
+ if (entry1File !== entry2File) {
+ return ts.compareValues(entry1File, entry2File);
+ }
+ var entry1Span = FindAllReferences.getTextSpanOfEntry(entry1);
+ var entry2Span = FindAllReferences.getTextSpanOfEntry(entry2);
+ return entry1Span.start !== entry2Span.start ?
+ ts.compareValues(entry1Span.start, entry2Span.start) :
+ ts.compareValues(entry1Span.length, entry2Span.length);
+ })
+ };
+ };
+ for (var _b = 0, references_1 = references; _b < references_1.length; _b++) {
+ var entry = references_1[_b];
+ _loop_3(entry);
+ }
+ }
+ return result;
+ }
+ function getSourceFileIndexOfEntry(program, entry) {
+ var sourceFile = entry.kind === 0 /* Span */ ?
+ program.getSourceFile(entry.fileName) :
+ entry.node.getSourceFile();
+ return program.getSourceFiles().indexOf(sourceFile);
}
function getReferencedSymbolsForModule(program, symbol, excludeImportTypeOfExportEquals, sourceFiles, sourceFilesSet) {
ts.Debug.assert(!!symbol.valueDeclaration);
@@ -99819,7 +99996,7 @@ var ts;
break;
default:
// This may be merged with something.
- ts.Debug.fail("Expected a module symbol to be declared by a SourceFile or ModuleDeclaration.");
+ ts.Debug.assert(!!(symbol.flags & 33554432 /* Transient */), "Expected a module symbol to be declared by a SourceFile or ModuleDeclaration.");
}
}
var exported = symbol.exports.get("export=" /* ExportEquals */);
@@ -99922,6 +100099,9 @@ var ts;
// If the symbol is declared as part of a declaration like `{ type: "a" } | { type: "b" }`, use the property on the union type to get more references.
return ts.firstDefined(symbol.declarations, function (decl) {
if (!decl.parent) {
+ // Ignore UMD module and global merge
+ if (symbol.flags & 33554432 /* Transient */)
+ return undefined;
// Assertions for GH#21814. We should be handling SourceFile symbols in `getReferencedSymbolsForModule` instead of getting here.
ts.Debug.fail("Unexpected symbol at " + ts.Debug.showSyntaxKind(node) + ": " + ts.Debug.showSymbol(symbol));
}
@@ -99936,6 +100116,12 @@ var ts;
SpecialSearchKind[SpecialSearchKind["Constructor"] = 1] = "Constructor";
SpecialSearchKind[SpecialSearchKind["Class"] = 2] = "Class";
})(SpecialSearchKind || (SpecialSearchKind = {}));
+ function getNonModuleSymbolOfMergedModuleSymbol(symbol) {
+ if (!(symbol.flags & (1536 /* Module */ | 33554432 /* Transient */)))
+ return undefined;
+ var decl = symbol.declarations && ts.find(symbol.declarations, function (d) { return !ts.isSourceFile(d) && !ts.isModuleDeclaration(d); });
+ return decl && decl.symbol;
+ }
/**
* Holds all state needed for the finding references.
* Unlike `Search`, there is only one `State`.
@@ -99994,7 +100180,7 @@ var ts;
// Note: getLocalSymbolForExportDefault handles `export default class C {}`, but not `export default C` or `export { C as default }`.
// The other two forms seem to be handled downstream (e.g. in `skipPastExportOrImportSpecifier`), so special-casing the first form
// here appears to be intentional).
- var _a = searchOptions.text, text = _a === void 0 ? ts.stripQuotes(ts.unescapeLeadingUnderscores((ts.getLocalSymbolForExportDefault(symbol) || symbol).escapedName)) : _a, _b = searchOptions.allSearchSymbols, allSearchSymbols = _b === void 0 ? [symbol] : _b;
+ var _a = searchOptions.text, text = _a === void 0 ? ts.stripQuotes(ts.unescapeLeadingUnderscores((ts.getLocalSymbolForExportDefault(symbol) || getNonModuleSymbolOfMergedModuleSymbol(symbol) || symbol).escapedName)) : _a, _b = searchOptions.allSearchSymbols, allSearchSymbols = _b === void 0 ? [symbol] : _b;
var escapedText = ts.escapeLeadingUnderscores(text);
var parents = this.options.implementations && location ? getParentSymbolsOfPropertyAccess(location, symbol, this.checker) : undefined;
return { symbol: symbol, comingFrom: comingFrom, text: text, escapedText: escapedText, parents: parents, allSearchSymbols: allSearchSymbols, includes: function (sym) { return ts.contains(allSearchSymbols, sym); } };
@@ -100830,6 +101016,13 @@ var ts;
if (res2)
return res2;
}
+ var aliasedSymbol = getMergedAliasedSymbolOfNamespaceExportDeclaration(location, symbol, checker);
+ if (aliasedSymbol) {
+ // In case of UMD module and global merging, search for global as well
+ var res_2 = cbSymbol(aliasedSymbol, /*rootSymbol*/ undefined, /*baseSymbol*/ undefined, 1 /* Node */);
+ if (res_2)
+ return res_2;
+ }
var res = fromRoot(symbol);
if (res)
return res;
@@ -100926,7 +101119,8 @@ var ts;
Core.getIntersectingMeaningFromDeclarations = getIntersectingMeaningFromDeclarations;
function isImplementation(node) {
return !!(node.flags & 4194304 /* Ambient */)
- || (ts.isVariableLike(node) ? ts.hasInitializer(node)
+ ? !(ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node))
+ : (ts.isVariableLike(node) ? ts.hasInitializer(node)
: ts.isFunctionLikeDeclaration(node) ? !!node.body
: ts.isClassLike(node) || ts.isModuleOrEnumDeclaration(node));
}
@@ -101084,7 +101278,7 @@ var ts;
}
function updateImports(program, changeTracker, oldToNew, newToOld, host, getCanonicalFileName) {
var allFiles = program.getSourceFiles();
- var _loop_3 = function (sourceFile) {
+ var _loop_4 = function (sourceFile) {
var newFromOld = oldToNew(sourceFile.path);
var newImportFromPath = newFromOld !== undefined ? newFromOld : sourceFile.path;
var newImportFromDirectory = ts.getDirectoryPath(newImportFromPath);
@@ -101116,7 +101310,7 @@ var ts;
};
for (var _i = 0, allFiles_1 = allFiles; _i < allFiles_1.length; _i++) {
var sourceFile = allFiles_1[_i];
- _loop_3(sourceFile);
+ _loop_4(sourceFile);
}
}
function combineNormal(pathA, pathB) {
@@ -101906,7 +102100,7 @@ var ts;
if (!patternMatcher)
return ts.emptyArray;
var rawItems = [];
- var _loop_4 = function (sourceFile) {
+ var _loop_5 = function (sourceFile) {
cancellationToken.throwIfCancellationRequested();
if (excludeDtsFiles && sourceFile.isDeclarationFile) {
return "continue";
@@ -101918,7 +102112,7 @@ var ts;
// Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[]
for (var _i = 0, sourceFiles_4 = sourceFiles; _i < sourceFiles_4.length; _i++) {
var sourceFile = sourceFiles_4[_i];
- _loop_4(sourceFile);
+ _loop_5(sourceFile);
}
rawItems.sort(compareNavigateToItems);
return (maxResultCount === undefined ? rawItems : rawItems.slice(0, maxResultCount)).map(createNavigateToItem);
@@ -103446,13 +103640,13 @@ var ts;
// Assumes 'value' is already lowercase.
function indexOfIgnoringCase(str, value) {
var n = str.length - value.length;
- var _loop_5 = function (start) {
+ var _loop_6 = function (start) {
if (every(value, function (valueChar, i) { return toLowerCase(str.charCodeAt(i + start)) === valueChar; })) {
return { value: start };
}
};
for (var start = 0; start <= n; start++) {
- var state_1 = _loop_5(start);
+ var state_1 = _loop_6(start);
if (typeof state_1 === "object")
return state_1.value;
}
@@ -104465,7 +104659,7 @@ var ts;
return ts.createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart);
}
function getContainingArgumentInfo(node, position, sourceFile, checker, isManuallyInvoked) {
- var _loop_6 = function (n) {
+ var _loop_7 = function (n) {
// If the node is not a subspan of its parent, this is a big problem.
// There have been crashes that might be caused by this violation.
ts.Debug.assert(ts.rangeContainsRange(n.parent, n), "Not a subspan", function () { return "Child: " + ts.Debug.showSyntaxKind(n) + ", parent: " + ts.Debug.showSyntaxKind(n.parent); });
@@ -104474,8 +104668,8 @@ var ts;
return { value: argumentInfo };
}
};
- for (var n = node; isManuallyInvoked || (!ts.isBlock(n) && !ts.isSourceFile(n)); n = n.parent) {
- var state_2 = _loop_6(n);
+ for (var n = node; !ts.isSourceFile(n) && (isManuallyInvoked || !ts.isBlock(n)); n = n.parent) {
+ var state_2 = _loop_7(n);
if (typeof state_2 === "object")
return state_2.value;
}
@@ -105632,7 +105826,7 @@ var ts;
return typeof o.type === "object" && !ts.forEachEntry(o.type, function (v) { return typeof v !== "number"; });
});
options = ts.cloneCompilerOptions(options);
- var _loop_7 = function (opt) {
+ var _loop_8 = function (opt) {
if (!ts.hasProperty(options, opt.name)) {
return "continue";
}
@@ -105651,7 +105845,7 @@ var ts;
};
for (var _i = 0, commandLineOptionsStringToEnum_1 = commandLineOptionsStringToEnum; _i < commandLineOptionsStringToEnum_1.length; _i++) {
var opt = commandLineOptionsStringToEnum_1[_i];
- _loop_7(opt);
+ _loop_8(opt);
}
return options;
}
@@ -108823,7 +109017,7 @@ var ts;
ChangeTracker.prototype.finishDeleteDeclarations = function () {
var _this = this;
var deletedNodesInLists = new ts.NodeSet(); // Stores nodes in lists that we already deleted. Used to avoid deleting `, ` twice in `a, b`.
- var _loop_8 = function (sourceFile, node) {
+ var _loop_9 = function (sourceFile, node) {
if (!this_1.deletedNodes.some(function (d) { return d.sourceFile === sourceFile && ts.rangeContainsRangeExclusive(d.node, node); })) {
if (ts.isArray(node)) {
this_1.deleteRange(sourceFile, ts.rangeOfTypeParameters(node));
@@ -108836,7 +109030,7 @@ var ts;
var this_1 = this;
for (var _i = 0, _a = this.deletedNodes; _i < _a.length; _i++) {
var _b = _a[_i], sourceFile = _b.sourceFile, node = _b.node;
- _loop_8(sourceFile, node);
+ _loop_9(sourceFile, node);
}
deletedNodesInLists.forEach(function (node) {
var sourceFile = node.getSourceFile();
@@ -108893,14 +109087,14 @@ var ts;
// order changes by start position
// If the start position is the same, put the shorter range first, since an empty range (x, x) may precede (x, y) but not vice-versa.
var normalized = ts.stableSort(changesInFile, function (a, b) { return (a.range.pos - b.range.pos) || (a.range.end - b.range.end); });
- var _loop_9 = function (i) {
+ var _loop_10 = function (i) {
ts.Debug.assert(normalized[i].range.end <= normalized[i + 1].range.pos, "Changes overlap", function () {
return JSON.stringify(normalized[i].range) + " and " + JSON.stringify(normalized[i + 1].range);
});
};
// verify that change intervals do not overlap, except possibly at end points.
for (var i = 0; i < normalized.length - 1; i++) {
- _loop_9(i);
+ _loop_10(i);
}
var textChanges = normalized.map(function (c) {
return ts.createTextChange(ts.createTextSpanFromRange(c.range), computeNewText(c, sourceFile, newLineCharacter, formatContext, validate));
@@ -110030,8 +110224,8 @@ var ts;
(function (InferFromReference) {
function inferTypesFromReferences(references, checker, cancellationToken) {
var usageContext = {};
- for (var _i = 0, references_1 = references; _i < references_1.length; _i++) {
- var reference = references_1[_i];
+ for (var _i = 0, references_2 = references; _i < references_2.length; _i++) {
+ var reference = references_2[_i];
cancellationToken.throwIfCancellationRequested();
inferTypeFromContext(reference, checker, usageContext);
}
@@ -110047,8 +110241,8 @@ var ts;
return undefined;
}
var usageContext = {};
- for (var _i = 0, references_2 = references; _i < references_2.length; _i++) {
- var reference = references_2[_i];
+ for (var _i = 0, references_3 = references; _i < references_3.length; _i++) {
+ var reference = references_3[_i];
cancellationToken.throwIfCancellationRequested();
inferTypeFromContext(reference, checker, usageContext);
}
@@ -110688,7 +110882,7 @@ var ts;
var newNodes = transformExpression(node, transformer, node);
changes.replaceNodeWithNodes(sourceFile, nodeToReplace, newNodes);
}
- var _loop_10 = function (statement) {
+ var _loop_11 = function (statement) {
ts.forEachChild(statement, function visit(node) {
if (ts.isCallExpression(node)) {
startTransformation(node, statement);
@@ -110700,7 +110894,7 @@ var ts;
};
for (var _i = 0, returnStatements_1 = returnStatements; _i < returnStatements_1.length; _i++) {
var statement = returnStatements_1[_i];
- _loop_10(statement);
+ _loop_11(statement);
}
}
function getReturnStatementsWithPromiseHandlers(body) {
@@ -112352,7 +112546,7 @@ var ts;
});
typeDeclToMembers.forEach(function (infos, classDeclaration) {
var supers = getAllSupers(classDeclaration, checker);
- var _loop_11 = function (info) {
+ var _loop_12 = function (info) {
// If some superclass added this property, don't add it again.
if (supers.some(function (superClassOrInterface) {
var superInfos = typeDeclToMembers.get(superClassOrInterface);
@@ -112379,7 +112573,7 @@ var ts;
};
for (var _i = 0, infos_1 = infos; _i < infos_1.length; _i++) {
var info = infos_1[_i];
- _loop_11(info);
+ _loop_12(info);
}
});
}));
@@ -114653,7 +114847,7 @@ var ts;
});
var namespaceImportName = namespaceNameConflicts ? ts.getUniqueName(preferredName, sourceFile) : preferredName;
var neededNamedImports = [];
- var _loop_12 = function (element) {
+ var _loop_13 = function (element) {
var propertyName = (element.propertyName || element.name).text;
ts.FindAllReferences.Core.eachSymbolReferenceInFile(element.name, checker, sourceFile, function (id) {
var access = ts.createPropertyAccess(ts.createIdentifier(namespaceImportName), propertyName);
@@ -114672,7 +114866,7 @@ var ts;
};
for (var _i = 0, _a = toConvert.elements; _i < _a.length; _i++) {
var element = _a[_i];
- _loop_12(element);
+ _loop_13(element);
}
changes.replaceNode(sourceFile, toConvert, ts.createNamespaceImport(ts.createIdentifier(namespaceImportName)));
if (neededNamedImports.length) {
@@ -115902,7 +116096,7 @@ var ts;
: ts.getEnclosingBlockScopeContainer(scopes[0]);
ts.forEachChild(containingLexicalScopeOfExtraction, checkForUsedDeclarations);
}
- var _loop_13 = function (i) {
+ var _loop_14 = function (i) {
var scopeUsages = usagesPerScope[i];
// Special case: in the innermost scope, all usages are available.
// (The computed value reflects the value at the top-level of the scope, but the
@@ -115942,7 +116136,7 @@ var ts;
}
};
for (var i = 0; i < scopes.length; i++) {
- _loop_13(i);
+ _loop_14(i);
}
return { target: target, usagesPerScope: usagesPerScope, functionErrorsPerScope: functionErrorsPerScope, constantErrorsPerScope: constantErrorsPerScope, exposedVariableDeclarations: exposedVariableDeclarations };
function isInGenericContext(node) {
@@ -116493,10 +116687,10 @@ var ts;
}
function updateImportsInOtherFiles(changes, program, oldFile, movedSymbols, newModuleName) {
var checker = program.getTypeChecker();
- var _loop_14 = function (sourceFile) {
+ var _loop_15 = function (sourceFile) {
if (sourceFile === oldFile)
return "continue";
- var _loop_15 = function (statement) {
+ var _loop_16 = function (statement) {
forEachImportInStatement(statement, function (importNode) {
if (checker.getSymbolAtLocation(moduleSpecifierFromImport(importNode)) !== oldFile.symbol)
return;
@@ -116518,12 +116712,12 @@ var ts;
};
for (var _i = 0, _a = sourceFile.statements; _i < _a.length; _i++) {
var statement = _a[_i];
- _loop_15(statement);
+ _loop_16(statement);
}
};
for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) {
var sourceFile = _a[_i];
- _loop_14(sourceFile);
+ _loop_15(sourceFile);
}
}
function getNamespaceLikeImport(node) {
@@ -116766,6 +116960,11 @@ var ts;
var movedSymbols = new SymbolSet();
var oldImportsNeededByNewFile = new SymbolSet();
var newFileImportsFromOldFile = new SymbolSet();
+ var containsJsx = ts.find(toMove, function (statement) { return !!(statement.transformFlags & 4 /* ContainsJsx */); });
+ var jsxNamespaceSymbol = getJsxNamespaceSymbol(containsJsx);
+ if (jsxNamespaceSymbol) { // Might not exist (e.g. in non-compiling code)
+ oldImportsNeededByNewFile.add(jsxNamespaceSymbol);
+ }
for (var _i = 0, toMove_1 = toMove; _i < toMove_1.length; _i++) {
var statement = toMove_1[_i];
forEachTopLevelDeclaration(statement, function (decl) {
@@ -116794,6 +116993,10 @@ var ts;
var statement = _c[_b];
if (ts.contains(toMove, statement))
continue;
+ // jsxNamespaceSymbol will only be set iff it is in oldImportsNeededByNewFile.
+ if (jsxNamespaceSymbol && !!(statement.transformFlags & 4 /* ContainsJsx */)) {
+ unusedImportsFromOldFile.delete(jsxNamespaceSymbol);
+ }
forEachReference(statement, checker, function (symbol) {
if (movedSymbols.has(symbol))
oldFileImportsFromNewFile.add(symbol);
@@ -116801,6 +117004,19 @@ var ts;
});
}
return { movedSymbols: movedSymbols, newFileImportsFromOldFile: newFileImportsFromOldFile, oldFileImportsFromNewFile: oldFileImportsFromNewFile, oldImportsNeededByNewFile: oldImportsNeededByNewFile, unusedImportsFromOldFile: unusedImportsFromOldFile };
+ function getJsxNamespaceSymbol(containsJsx) {
+ if (containsJsx === undefined) {
+ return undefined;
+ }
+ var jsxNamespace = checker.getJsxNamespace(containsJsx);
+ // Strictly speaking, this could resolve to a symbol other than the JSX namespace.
+ // This will produce erroneous output (probably, an incorrectly copied import) but
+ // is expected to be very rare and easily reversible.
+ var jsxNamespaceSymbol = checker.resolveName(jsxNamespace, containsJsx, 1920 /* Namespace */, /*excludeGlobals*/ true);
+ return !!jsxNamespaceSymbol && ts.some(jsxNamespaceSymbol.declarations, isInImport)
+ ? jsxNamespaceSymbol
+ : undefined;
+ }
}
// Below should all be utilities
function isInImport(decl) {
@@ -116819,7 +117035,7 @@ var ts;
}
function isVariableDeclarationInImport(decl) {
return ts.isSourceFile(decl.parent.parent.parent) &&
- decl.initializer && ts.isRequireCall(decl.initializer, /*checkArgumentIsStringLiteralLike*/ true);
+ !!decl.initializer && ts.isRequireCall(decl.initializer, /*checkArgumentIsStringLiteralLike*/ true);
}
function filterImport(i, moduleSpecifier, keep) {
switch (i.kind) {
@@ -128528,6 +128744,12 @@ var ts;
process.noAsar = true;
// Start listening
ioSession.listen();
+ if (ts.Debug.isDebugging) {
+ ts.Debug.enableDebugInfo();
+ }
+ if (ts.sys.tryEnableSourceMapsForHost && /^development$/i.test(ts.sys.getEnvironmentVariable("NODE_ENV"))) {
+ ts.sys.tryEnableSourceMapsForHost();
+ }
})(server = ts.server || (ts.server = {}));
})(ts || (ts = {}));
//# sourceMappingURL=tsserver.js.map
\ No newline at end of file
diff --git a/lib/tsserverlibrary.d.ts b/lib/tsserverlibrary.d.ts
index 383ca7536f40b..ae457551a5003 100644
--- a/lib/tsserverlibrary.d.ts
+++ b/lib/tsserverlibrary.d.ts
@@ -1726,15 +1726,18 @@ declare namespace ts {
}
interface InputFiles extends Node {
kind: SyntaxKind.InputFiles;
+ javascriptPath?: string;
javascriptText: string;
javascriptMapPath?: string;
javascriptMapText?: string;
+ declarationPath?: string;
declarationText: string;
declarationMapPath?: string;
declarationMapText?: string;
}
interface UnparsedSource extends Node {
kind: SyntaxKind.UnparsedSource;
+ fileName?: string;
text: string;
sourceMapPath?: string;
sourceMapText?: string;
@@ -2214,6 +2217,7 @@ declare namespace ts {
}
interface UniqueESSymbolType extends Type {
symbol: Symbol;
+ escapedName: __String;
}
interface StringLiteralType extends LiteralType {
value: string;
@@ -3097,6 +3101,7 @@ declare namespace ts {
scanJsxIdentifier(): SyntaxKind;
scanJsxAttributeValue(): SyntaxKind;
reScanJsxToken(): JsxTokenSyntaxKind;
+ reScanLessThanToken(): SyntaxKind;
scanJsxToken(): JsxTokenSyntaxKind;
scanJSDocToken(): JsDocSyntaxKind;
scan(): SyntaxKind;
@@ -3978,9 +3983,11 @@ declare namespace ts {
function updateCommaList(node: CommaListExpression, elements: ReadonlyArray): CommaListExpression;
function createBundle(sourceFiles: ReadonlyArray, prepends?: ReadonlyArray): Bundle;
function createUnparsedSourceFile(text: string): UnparsedSource;
+ function createUnparsedSourceFile(inputFile: InputFiles, type: "js" | "dts"): UnparsedSource;
function createUnparsedSourceFile(text: string, mapPath: string | undefined, map: string | undefined): UnparsedSource;
- function createInputFiles(javascript: string, declaration: string): InputFiles;
- function createInputFiles(javascript: string, declaration: string, javascriptMapPath: string | undefined, javascriptMapText: string | undefined, declarationMapPath: string | undefined, declarationMapText: string | undefined): InputFiles;
+ function createInputFiles(javascriptText: string, declarationText: string): InputFiles;
+ function createInputFiles(readFileText: (path: string) => string | undefined, javascriptPath: string, javascriptMapPath: string | undefined, declarationPath: string, declarationMapPath: string | undefined): InputFiles;
+ function createInputFiles(javascriptText: string, declarationText: string, javascriptMapPath: string | undefined, javascriptMapText: string | undefined, declarationMapPath: string | undefined, declarationMapText: string | undefined): InputFiles;
function updateBundle(node: Bundle, sourceFiles: ReadonlyArray, prepends?: ReadonlyArray): Bundle;
function createImmediatelyInvokedFunctionExpression(statements: ReadonlyArray): CallExpression;
function createImmediatelyInvokedFunctionExpression(statements: ReadonlyArray, param: ParameterDeclaration, paramValue: Expression): CallExpression;
@@ -7932,8 +7939,8 @@ declare namespace ts.server.protocol {
readonly importModuleSpecifierPreference?: "relative" | "non-relative";
readonly allowTextChangesInNewFiles?: boolean;
readonly lazyConfiguredProjectsFromExternalProject?: boolean;
- readonly allowRenameOfImportPath?: boolean;
readonly providePrefixAndSuffixTextForRename?: boolean;
+ readonly allowRenameOfImportPath?: boolean;
}
interface CompilerOptions {
allowJs?: boolean;
diff --git a/lib/tsserverlibrary.js b/lib/tsserverlibrary.js
index 24e254e580c85..f2ff48d023c53 100644
--- a/lib/tsserverlibrary.js
+++ b/lib/tsserverlibrary.js
@@ -84,7 +84,7 @@ var ts;
// If changing the text in this section, be sure to test `configureNightly` too.
ts.versionMajorMinor = "3.3";
/** The version of the TypeScript compiler release */
- ts.version = ts.versionMajorMinor + ".0-rc";
+ ts.version = ts.versionMajorMinor + ".1";
})(ts || (ts = {}));
(function (ts) {
/* @internal */
@@ -5529,7 +5529,6 @@ var ts;
Property_0_is_used_before_being_assigned: diag(2565, ts.DiagnosticCategory.Error, "Property_0_is_used_before_being_assigned_2565", "Property '{0}' is used before being assigned."),
A_rest_element_cannot_have_a_property_name: diag(2566, ts.DiagnosticCategory.Error, "A_rest_element_cannot_have_a_property_name_2566", "A rest element cannot have a property name."),
Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations: diag(2567, ts.DiagnosticCategory.Error, "Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations_2567", "Enum declarations can only merge with namespace or other enum declarations."),
- Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators: diag(2568, ts.DiagnosticCategory.Error, "Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators_2568", "Type '{0}' is not an array type. Use compiler option '--downlevelIteration' to allow iterating of iterators."),
Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators: diag(2569, ts.DiagnosticCategory.Error, "Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterati_2569", "Type '{0}' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators."),
Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await: diag(2570, ts.DiagnosticCategory.Error, "Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await_2570", "Property '{0}' does not exist on type '{1}'. Did you forget to use 'await'?"),
Object_is_of_type_unknown: diag(2571, ts.DiagnosticCategory.Error, "Object_is_of_type_unknown_2571", "Object is of type 'unknown'."),
@@ -5624,7 +5623,7 @@ var ts;
Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor: diag(2715, ts.DiagnosticCategory.Error, "Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor_2715", "Abstract property '{0}' in class '{1}' cannot be accessed in the constructor."),
Type_parameter_0_has_a_circular_default: diag(2716, ts.DiagnosticCategory.Error, "Type_parameter_0_has_a_circular_default_2716", "Type parameter '{0}' has a circular default."),
Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_type_2: diag(2717, ts.DiagnosticCategory.Error, "Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_t_2717", "Subsequent property declarations must have the same type. Property '{0}' must be of type '{1}', but here has type '{2}'."),
- Duplicate_declaration_0: diag(2718, ts.DiagnosticCategory.Error, "Duplicate_declaration_0_2718", "Duplicate declaration '{0}'."),
+ Duplicate_property_0: diag(2718, ts.DiagnosticCategory.Error, "Duplicate_property_0_2718", "Duplicate property '{0}'."),
Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated: diag(2719, ts.DiagnosticCategory.Error, "Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated_2719", "Type '{0}' is not assignable to type '{1}'. Two different types with this name exist, but they are unrelated."),
Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass: diag(2720, ts.DiagnosticCategory.Error, "Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclas_2720", "Class '{0}' incorrectly implements class '{1}'. Did you mean to extend '{1}' and inherit its members as a subclass?"),
Cannot_invoke_an_object_which_is_possibly_null: diag(2721, ts.DiagnosticCategory.Error, "Cannot_invoke_an_object_which_is_possibly_null_2721", "Cannot invoke an object which is possibly 'null'."),
@@ -5639,6 +5638,7 @@ var ts;
An_arrow_function_cannot_have_a_this_parameter: diag(2730, ts.DiagnosticCategory.Error, "An_arrow_function_cannot_have_a_this_parameter_2730", "An arrow function cannot have a 'this' parameter."),
Implicit_conversion_of_a_symbol_to_a_string_will_fail_at_runtime_Consider_wrapping_this_expression_in_String: diag(2731, ts.DiagnosticCategory.Error, "Implicit_conversion_of_a_symbol_to_a_string_will_fail_at_runtime_Consider_wrapping_this_expression_i_2731", "Implicit conversion of a 'symbol' to a 'string' will fail at runtime. Consider wrapping this expression in 'String(...)'."),
Cannot_find_module_0_Consider_using_resolveJsonModule_to_import_module_with_json_extension: diag(2732, ts.DiagnosticCategory.Error, "Cannot_find_module_0_Consider_using_resolveJsonModule_to_import_module_with_json_extension_2732", "Cannot find module '{0}'. Consider using '--resolveJsonModule' to import module with '.json' extension"),
+ Property_0_was_also_declared_here: diag(2733, ts.DiagnosticCategory.Error, "Property_0_was_also_declared_here_2733", "Property '{0}' was also declared here."),
It_is_highly_likely_that_you_are_missing_a_semicolon: diag(2734, ts.DiagnosticCategory.Error, "It_is_highly_likely_that_you_are_missing_a_semicolon_2734", "It is highly likely that you are missing a semicolon."),
Did_you_mean_for_0_to_be_constrained_to_type_new_args_Colon_any_1: diag(2735, ts.DiagnosticCategory.Error, "Did_you_mean_for_0_to_be_constrained_to_type_new_args_Colon_any_1_2735", "Did you mean for '{0}' to be constrained to type 'new (...args: any[]) => {1}'?"),
Operator_0_cannot_be_applied_to_type_1: diag(2736, ts.DiagnosticCategory.Error, "Operator_0_cannot_be_applied_to_type_1_2736", "Operator '{0}' cannot be applied to type '{1}'."),
@@ -6926,6 +6926,7 @@ var ts;
scanJsxIdentifier: scanJsxIdentifier,
scanJsxAttributeValue: scanJsxAttributeValue,
reScanJsxToken: reScanJsxToken,
+ reScanLessThanToken: reScanLessThanToken,
scanJsxToken: scanJsxToken,
scanJSDocToken: scanJSDocToken,
scan: scan,
@@ -7922,6 +7923,13 @@ var ts;
pos = tokenPos = startPos;
return token = scanJsxToken();
}
+ function reScanLessThanToken() {
+ if (token === 46 /* LessThanLessThanToken */) {
+ pos = tokenPos + 1;
+ return token = 28 /* LessThanToken */;
+ }
+ return token;
+ }
function scanJsxToken() {
startPos = tokenPos = pos;
if (pos >= end) {
@@ -8858,7 +8866,9 @@ var ts;
case 14 /* NoSubstitutionTemplateLiteral */:
return ts.escapeLeadingUnderscores(name.text);
case 149 /* ComputedPropertyName */:
- return isStringOrNumericLiteralLike(name.expression) ? ts.escapeLeadingUnderscores(name.expression.text) : undefined; // TODO: GH#18217 Almost all uses of this assume the result to be defined!
+ if (isStringOrNumericLiteralLike(name.expression))
+ return ts.escapeLeadingUnderscores(name.expression.text);
+ return ts.Debug.fail("Text of property name cannot be read from non-literal-valued ComputedPropertyNames");
default:
return ts.Debug.assertNever(name);
}
@@ -17204,6 +17214,9 @@ var ts;
function reScanTemplateToken() {
return currentToken = scanner.reScanTemplateToken();
}
+ function reScanLessThanToken() {
+ return currentToken = scanner.reScanLessThanToken();
+ }
function scanJsxIdentifier() {
return currentToken = scanner.scanJsxIdentifier();
}
@@ -18215,7 +18228,7 @@ var ts;
function parseTypeReference() {
var node = createNode(164 /* TypeReference */);
node.typeName = parseEntityName(/*allowReservedWords*/ true, ts.Diagnostics.Type_expected);
- if (!scanner.hasPrecedingLineBreak() && token() === 28 /* LessThanToken */) {
+ if (!scanner.hasPrecedingLineBreak() && reScanLessThanToken() === 28 /* LessThanToken */) {
node.typeArguments = parseBracketedList(20 /* TypeArguments */, parseType, 28 /* LessThanToken */, 30 /* GreaterThanToken */);
}
return finishNode(node);
@@ -20237,7 +20250,8 @@ var ts;
function parseCallExpressionRest(expression) {
while (true) {
expression = parseMemberExpressionRest(expression);
- if (token() === 28 /* LessThanToken */) {
+ // handle 'foo<()'
+ if (token() === 28 /* LessThanToken */ || token() === 46 /* LessThanLessThanToken */) {
// See if this is the start of a generic invocation. If so, consume it and
// keep checking for postfix expressions. Otherwise, it's just a '<' that's
// part of an arithmetic expression. Break out so we consume it higher in the
@@ -20274,9 +20288,10 @@ var ts;
return result;
}
function parseTypeArgumentsInExpression() {
- if (!parseOptional(28 /* LessThanToken */)) {
+ if (reScanLessThanToken() !== 28 /* LessThanToken */) {
return undefined;
}
+ nextToken();
var typeArguments = parseDelimitedList(20 /* TypeArguments */, parseType);
if (!parseExpected(30 /* GreaterThanToken */)) {
// If it doesn't have the closing `>` then it's definitely not an type argument list.
@@ -27149,6 +27164,7 @@ var ts;
ContainerFlags[ContainerFlags["IsInterface"] = 64] = "IsInterface";
ContainerFlags[ContainerFlags["IsObjectLiteralOrClassExpressionMethod"] = 128] = "IsObjectLiteralOrClassExpressionMethod";
})(ContainerFlags || (ContainerFlags = {}));
+ var flowNodeCreated = ts.identity;
var binder = createBinder();
function bindSourceFile(file, options) {
ts.performance.mark("beforeBind");
@@ -27537,6 +27553,7 @@ var ts;
blockScopeContainer.locals = undefined;
}
if (containerFlags & 4 /* IsControlFlowContainer */) {
+ var saveFlowNodeCreated = flowNodeCreated;
var saveCurrentFlow = currentFlow;
var saveBreakTarget = currentBreakTarget;
var saveContinueTarget = currentContinueTarget;
@@ -27560,6 +27577,7 @@ var ts;
currentContinueTarget = undefined;
activeLabels = undefined;
hasExplicitReturn = false;
+ flowNodeCreated = ts.identity;
bindChildren(node);
// Reset all reachability check related flags on node (for incremental scenarios)
node.flags &= ~1408 /* ReachabilityAndEmitFlags */;
@@ -27586,6 +27604,7 @@ var ts;
currentReturnTarget = saveReturnTarget;
activeLabels = saveActiveLabels;
hasExplicitReturn = saveHasExplicitReturn;
+ flowNodeCreated = saveFlowNodeCreated;
}
else if (containerFlags & 64 /* IsInterface */) {
seenThisKeyword = false;
@@ -27849,22 +27868,22 @@ var ts;
return antecedent;
}
setFlowNodeReferenced(antecedent);
- return { flags: flags, expression: expression, antecedent: antecedent };
+ return flowNodeCreated({ flags: flags, expression: expression, antecedent: antecedent });
}
function createFlowSwitchClause(antecedent, switchStatement, clauseStart, clauseEnd) {
if (!isNarrowingExpression(switchStatement.expression)) {
return antecedent;
}
setFlowNodeReferenced(antecedent);
- return { flags: 128 /* SwitchClause */, switchStatement: switchStatement, clauseStart: clauseStart, clauseEnd: clauseEnd, antecedent: antecedent };
+ return flowNodeCreated({ flags: 128 /* SwitchClause */, switchStatement: switchStatement, clauseStart: clauseStart, clauseEnd: clauseEnd, antecedent: antecedent });
}
function createFlowAssignment(antecedent, node) {
setFlowNodeReferenced(antecedent);
- return { flags: 16 /* Assignment */, antecedent: antecedent, node: node };
+ return flowNodeCreated({ flags: 16 /* Assignment */, antecedent: antecedent, node: node });
}
function createFlowArrayMutation(antecedent, node) {
setFlowNodeReferenced(antecedent);
- var res = { flags: 256 /* ArrayMutation */, antecedent: antecedent, node: node };
+ var res = flowNodeCreated({ flags: 256 /* ArrayMutation */, antecedent: antecedent, node: node });
return res;
}
function finishFlowLabel(flow) {
@@ -28052,18 +28071,46 @@ var ts;
function bindTryStatement(node) {
var preFinallyLabel = createBranchLabel();
var preTryFlow = currentFlow;
- // TODO: Every statement in try block is potentially an exit point!
+ var tryPriors = [];
+ var oldFlowNodeCreated = flowNodeCreated;
+ // We hook the creation of all flow nodes within the `try` scope and store them so we can add _all_ of them
+ // as possible antecedents of the start of the `catch` or `finally` blocks.
+ // Don't bother intercepting the call if there's no finally or catch block that needs the information
+ if (node.catchClause || node.finallyBlock) {
+ flowNodeCreated = function (node) { return (tryPriors.push(node), node); };
+ }
bind(node.tryBlock);
+ flowNodeCreated = oldFlowNodeCreated;
addAntecedent(preFinallyLabel, currentFlow);
var flowAfterTry = currentFlow;
var flowAfterCatch = unreachableFlow;
if (node.catchClause) {
currentFlow = preTryFlow;
+ if (tryPriors.length) {
+ var preCatchFlow = createBranchLabel();
+ addAntecedent(preCatchFlow, currentFlow);
+ for (var _i = 0, tryPriors_1 = tryPriors; _i < tryPriors_1.length; _i++) {
+ var p = tryPriors_1[_i];
+ addAntecedent(preCatchFlow, p);
+ }
+ currentFlow = finishFlowLabel(preCatchFlow);
+ }
bind(node.catchClause);
addAntecedent(preFinallyLabel, currentFlow);
flowAfterCatch = currentFlow;
}
if (node.finallyBlock) {
+ // We add the nodes within the `try` block to the `finally`'s antecedents if there's no catch block
+ // (If there is a `catch` block, it will have all these antecedents instead, and the `finally` will
+ // have the end of the `try` block and the end of the `catch` block)
+ if (!node.catchClause) {
+ if (tryPriors.length) {
+ for (var _a = 0, tryPriors_2 = tryPriors; _a < tryPriors_2.length; _a++) {
+ var p = tryPriors_2[_a];
+ addAntecedent(preFinallyLabel, p);
+ }
+ }
+ }
// in finally flow is combined from pre-try/flow from try/flow from catch
// pre-flow is necessary to make sure that finally is reachable even if finally flows in both try and finally blocks are unreachable
// also for finally blocks we inject two extra edges into the flow graph.
@@ -28108,7 +28155,7 @@ var ts;
}
}
if (!(currentFlow.flags & 1 /* Unreachable */)) {
- var afterFinallyFlow = { flags: 4096 /* AfterFinally */, antecedent: currentFlow };
+ var afterFinallyFlow = flowNodeCreated({ flags: 4096 /* AfterFinally */, antecedent: currentFlow });
preFinallyFlow.lock = afterFinallyFlow;
currentFlow = afterFinallyFlow;
}
@@ -35634,16 +35681,17 @@ var ts;
var objectFlags = 128 /* ObjectLiteral */;
ts.forEach(pattern.elements, function (e) {
var name = e.propertyName || e.name;
- if (isComputedNonLiteralName(name)) {
- // do not include computed properties in the implied type
- objectFlags |= 512 /* ObjectLiteralPatternWithComputedProperties */;
- return;
- }
if (e.dotDotDotToken) {
stringIndexInfo = createIndexInfo(anyType, /*isReadonly*/ false);
return;
}
- var text = ts.getTextOfPropertyName(name);
+ var exprType = getLiteralTypeFromPropertyName(name);
+ if (!isTypeUsableAsPropertyName(exprType)) {
+ // do not include computed properties in the implied type
+ objectFlags |= 512 /* ObjectLiteralPatternWithComputedProperties */;
+ return;
+ }
+ var text = getPropertyNameFromType(exprType);
var flags = 4 /* Property */ | (e.initializer ? 16777216 /* Optional */ : 0);
var symbol = createSymbol(flags, text);
symbol.type = getTypeFromBindingElement(e, includePatternInType, reportErrors);
@@ -36685,9 +36733,9 @@ var ts;
return type;
}
/**
- * Indicates whether a type can be used as a late-bound name.
+ * Indicates whether a type can be used as a property name.
*/
- function isTypeUsableAsLateBoundName(type) {
+ function isTypeUsableAsPropertyName(type) {
return !!(type.flags & 8576 /* StringOrNumberLiteralOrUnique */);
}
/**
@@ -36701,7 +36749,7 @@ var ts;
function isLateBindableName(node) {
return ts.isComputedPropertyName(node)
&& ts.isEntityNameExpression(node.expression)
- && isTypeUsableAsLateBoundName(checkComputedPropertyName(node));
+ && isTypeUsableAsPropertyName(checkComputedPropertyName(node));
}
function isLateBoundName(name) {
return name.charCodeAt(0) === 95 /* _ */ &&
@@ -36728,11 +36776,11 @@ var ts;
return ts.isDynamicName(node) && !isLateBindableName(node);
}
/**
- * Gets the symbolic name for a late-bound member from its type.
+ * Gets the symbolic name for a member from its type.
*/
- function getLateBoundNameFromType(type) {
+ function getPropertyNameFromType(type) {
if (type.flags & 8192 /* UniqueESSymbol */) {
- return "__@" + type.symbol.escapedName + "@" + getSymbolId(type.symbol);
+ return type.escapedName;
}
if (type.flags & (128 /* StringLiteral */ | 256 /* NumberLiteral */)) {
return ts.escapeLeadingUnderscores("" + type.value);
@@ -36796,8 +36844,8 @@ var ts;
// fall back to the early-bound name of this member.
links.resolvedSymbol = decl.symbol;
var type = checkComputedPropertyName(decl.name);
- if (isTypeUsableAsLateBoundName(type)) {
- var memberName = getLateBoundNameFromType(type);
+ if (isTypeUsableAsPropertyName(type)) {
+ var memberName = getPropertyNameFromType(type);
var symbolFlags = decl.symbol.flags;
// Get or add a late-bound symbol for the member. This allows us to merge late-bound accessor declarations.
var lateSymbol = lateSymbols.get(memberName);
@@ -36811,9 +36859,9 @@ var ts;
// If we have an existing early-bound member, combine its declarations so that we can
// report an error at each declaration.
var declarations = earlySymbol ? ts.concatenate(earlySymbol.declarations, lateSymbol.declarations) : lateSymbol.declarations;
- var name_3 = ts.declarationNameToString(decl.name);
- ts.forEach(declarations, function (declaration) { return error(ts.getNameOfDeclaration(declaration) || declaration, ts.Diagnostics.Duplicate_declaration_0, name_3); });
- error(decl.name || decl, ts.Diagnostics.Duplicate_declaration_0, name_3);
+ var name_3 = !(type.flags & 8192 /* UniqueESSymbol */) && ts.unescapeLeadingUnderscores(memberName) || ts.declarationNameToString(decl.name);
+ ts.forEach(declarations, function (declaration) { return error(ts.getNameOfDeclaration(declaration) || declaration, ts.Diagnostics.Property_0_was_also_declared_here, name_3); });
+ error(decl.name || decl, ts.Diagnostics.Duplicate_property_0, name_3);
lateSymbol = createSymbol(0 /* None */, memberName, 2048 /* Late */);
}
lateSymbol.nameType = type;
@@ -37405,8 +37453,8 @@ var ts;
var propType = instantiateType(templateType, templateMapper);
// If the current iteration type constituent is a string literal type, create a property.
// Otherwise, for type string create a string index signature.
- if (t.flags & 8576 /* StringOrNumberLiteralOrUnique */) {
- var propName = getLateBoundNameFromType(t);
+ if (isTypeUsableAsPropertyName(t)) {
+ var propName = getPropertyNameFromType(t);
var modifiersProp = getPropertyOfType(modifiersType, propName);
var isOptional = !!(templateModifiers & 4 /* IncludeOptional */ ||
!(templateModifiers & 8 /* ExcludeOptional */) && modifiersProp && modifiersProp.flags & 16777216 /* Optional */);
@@ -37576,7 +37624,8 @@ var ts;
function isTypeInvalidDueToUnionDiscriminant(contextualType, obj) {
var list = obj.properties;
return list.some(function (property) {
- var name = property.name && ts.getTextOfPropertyName(property.name);
+ var nameType = property.name && getLiteralTypeFromPropertyName(property.name);
+ var name = nameType && isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined;
var expected = name === undefined ? undefined : getTypeOfPropertyOfType(contextualType, name);
return !!expected && isLiteralType(expected) && !isTypeIdenticalTo(getTypeOfNode(property), expected);
});
@@ -37946,6 +37995,10 @@ var ts;
result.containingType = containingType;
if (!hasNonUniformValueDeclaration && firstValueDeclaration) {
result.valueDeclaration = firstValueDeclaration;
+ // Inherit information about parent type.
+ if (firstValueDeclaration.symbol.parent) {
+ result.parent = firstValueDeclaration.symbol.parent;
+ }
}
result.declarations = declarations;
result.nameType = nameType;
@@ -38804,21 +38857,16 @@ var ts;
* the type of this reference is just the type of the value we resolved to.
*/
function getJSDocTypeReference(node, symbol, typeArguments) {
- if (!pushTypeResolution(symbol, 6 /* JSDocTypeReference */)) {
- return errorType;
- }
- var assignedType = getAssignedClassType(symbol);
- var valueType = getTypeOfSymbol(symbol);
- var referenceType = valueType.symbol && valueType.symbol !== symbol && !isInferredClassType(valueType) && getTypeReferenceTypeWorker(node, valueType.symbol, typeArguments);
- if (!popTypeResolution()) {
- getSymbolLinks(symbol).resolvedJSDocType = errorType;
- error(node, ts.Diagnostics.JSDoc_type_0_circularly_references_itself, symbolToString(symbol));
- return errorType;
- }
- if (referenceType || assignedType) {
- // TODO: GH#18217 (should the `|| assignedType` be at a lower precedence?)
- var type = (referenceType && assignedType ? getIntersectionType([assignedType, referenceType]) : referenceType || assignedType);
- return getSymbolLinks(symbol).resolvedJSDocType = type;
+ // In the case of an assignment of a function expression (binary expressions, variable declarations, etc.), we will get the
+ // correct instance type for the symbol on the LHS by finding the type for RHS. For example if we want to get the type of the symbol `foo`:
+ // var foo = function() {}
+ // We will find the static type of the assigned anonymous function.
+ var staticType = getTypeOfSymbol(symbol);
+ var instanceType = staticType.symbol &&
+ staticType.symbol !== symbol && // Make sure this is an assignment like expression by checking that symbol -> type -> symbol doesn't roundtrips.
+ getTypeReferenceTypeWorker(node, staticType.symbol, typeArguments); // Get the instance type of the RHS symbol.
+ if (instanceType) {
+ return getSymbolLinks(symbol).resolvedJSDocType = instanceType;
}
}
function getTypeReferenceTypeWorker(node, symbol, typeArguments) {
@@ -38836,8 +38884,11 @@ var ts;
}
if (symbol.flags & 16 /* Function */ &&
isJSDocTypeReference(node) &&
- (symbol.members || ts.getJSDocClassTag(symbol.valueDeclaration))) {
- return getInferredClassType(symbol);
+ isJSConstructor(symbol.valueDeclaration)) {
+ var resolved = resolveStructuredTypeMembers(getTypeOfSymbol(symbol));
+ if (resolved.callSignatures.length === 1) {
+ return getReturnTypeOfSignature(resolved.callSignatures[0]);
+ }
}
}
function getSubstitutionType(typeVariable, substitute) {
@@ -39734,8 +39785,8 @@ var ts;
}
function getPropertyTypeForIndexType(objectType, indexType, accessNode, cacheSymbol, missingType) {
var accessExpression = accessNode && accessNode.kind === 190 /* ElementAccessExpression */ ? accessNode : undefined;
- var propName = isTypeUsableAsLateBoundName(indexType) ?
- getLateBoundNameFromType(indexType) :
+ var propName = isTypeUsableAsPropertyName(indexType) ?
+ getPropertyNameFromType(indexType) :
accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ?
ts.getPropertyNameForKnownSymbolName(ts.idText(accessExpression.argumentExpression.name)) :
accessNode && ts.isPropertyName(accessNode) ?
@@ -40379,6 +40430,7 @@ var ts;
function createUniqueESSymbolType(symbol) {
var type = createType(8192 /* UniqueESSymbol */);
type.symbol = symbol;
+ type.escapedName = "__@" + type.symbol.escapedName + "@" + getSymbolId(type.symbol);
return type;
}
function getESSymbolLikeTypeForNode(node) {
@@ -40576,7 +40628,9 @@ var ts;
return type.flags & 262144 /* TypeParameter */ ? wildcardType : type;
}
function getRestrictiveTypeParameter(tp) {
- return !tp.constraint ? tp : tp.restrictiveInstantiation || (tp.restrictiveInstantiation = createTypeParameter(tp.symbol));
+ return tp.constraint === unknownType ? tp : tp.restrictiveInstantiation || (tp.restrictiveInstantiation = createTypeParameter(tp.symbol),
+ tp.restrictiveInstantiation.constraint = unknownType,
+ tp.restrictiveInstantiation);
}
function restrictiveMapper(type) {
return type.flags & 262144 /* TypeParameter */ ? getRestrictiveTypeParameter(type) : type;
@@ -41191,7 +41245,7 @@ var ts;
}
if (resultObj.error) {
var reportedDiag = resultObj.error;
- var propertyName = isTypeUsableAsLateBoundName(nameType) ? getLateBoundNameFromType(nameType) : undefined;
+ var propertyName = isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined;
var targetProp = propertyName !== undefined ? getPropertyOfType(target, propertyName) : undefined;
var issuedElaboration = false;
if (!targetProp) {
@@ -42547,7 +42601,7 @@ var ts;
}
else {
// An empty object type is related to any mapped type that includes a '?' modifier.
- if (isPartialMappedType(target) && isEmptyObjectType(source)) {
+ if (relation !== subtypeRelation && isPartialMappedType(target) && isEmptyObjectType(source)) {
return -1 /* True */;
}
if (isGenericMappedType(target)) {
@@ -44351,7 +44405,11 @@ var ts;
priority |= 4 /* MappedTypeConstraint */;
inferFromTypes(getIndexType(source), constraintType);
priority = savePriority;
- inferFromTypes(getUnionType(ts.map(getPropertiesOfType(source), getTypeOfSymbol)), getTemplateTypeFromMappedType(target));
+ var valueTypes = ts.compact([
+ getIndexTypeOfType(source, 0 /* String */),
+ getIndexTypeOfType(source, 1 /* Number */)
+ ].concat(ts.map(getPropertiesOfType(source), getTypeOfSymbol)));
+ inferFromTypes(getUnionType(valueTypes), getTemplateTypeFromMappedType(target));
return true;
}
return false;
@@ -44908,7 +44966,10 @@ var ts;
return type;
}
function getTypeOfDestructuredProperty(type, name) {
- var text = ts.getTextOfPropertyName(name);
+ var nameType = getLiteralTypeFromPropertyName(name);
+ if (!isTypeUsableAsPropertyName(nameType))
+ return errorType;
+ var text = getPropertyNameFromType(nameType);
return getConstraintForLocation(getTypeOfPropertyOfType(type, text), name) ||
isNumericLiteralName(text) && getIndexTypeOfType(type, 1 /* Number */) ||
getIndexTypeOfType(type, 0 /* String */) ||
@@ -45466,9 +45527,6 @@ var ts;
}
function getTypeAtSwitchClause(flow) {
var expr = flow.switchStatement.expression;
- if (containsMatchingReferenceDiscriminant(reference, expr)) {
- return declaredType;
- }
var flowType = getTypeAtFlowNode(flow.antecedent);
var type = getTypeFromFlowType(flowType);
if (isMatchingReference(reference, expr)) {
@@ -45480,6 +45538,9 @@ var ts;
else if (expr.kind === 199 /* TypeOfExpression */ && isMatchingReference(reference, expr.expression)) {
type = narrowBySwitchOnTypeOf(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd);
}
+ else if (containsMatchingReferenceDiscriminant(reference, expr)) {
+ type = declaredType;
+ }
return createFlowType(type, isIncomplete(flowType));
}
function getTypeAtFlowBranchLabel(flow) {
@@ -46472,7 +46533,7 @@ var ts;
else if (isInJS &&
(container.kind === 196 /* FunctionExpression */ || container.kind === 239 /* FunctionDeclaration */) &&
ts.getJSDocClassTag(container)) {
- var classType = getJSClassType(container.symbol);
+ var classType = getJSClassType(getMergedSymbol(container.symbol));
if (classType) {
return getFlowTypeOfReference(node, classType);
}
@@ -46867,9 +46928,10 @@ var ts;
var parentDeclaration = declaration.parent.parent;
var name = declaration.propertyName || declaration.name;
var parentType = getContextualTypeForVariableLikeDeclaration(parentDeclaration);
- if (parentType && !ts.isBindingPattern(name)) {
- var text = ts.getTextOfPropertyName(name);
- if (text !== undefined) {
+ if (parentType && !ts.isBindingPattern(name) && !isComputedNonLiteralName(name)) {
+ var nameType = getLiteralTypeFromPropertyName(name);
+ if (isTypeUsableAsPropertyName(nameType)) {
+ var text = getPropertyNameFromType(nameType);
return getTypeOfPropertyOfType(parentType, text);
}
}
@@ -47743,10 +47805,9 @@ var ts;
}
}
typeFlags |= type.flags;
- var nameType = computedNameType && computedNameType.flags & 8576 /* StringOrNumberLiteralOrUnique */ ?
- computedNameType : undefined;
+ var nameType = computedNameType && isTypeUsableAsPropertyName(computedNameType) ? computedNameType : undefined;
var prop = nameType ?
- createSymbol(4 /* Property */ | member.flags, getLateBoundNameFromType(nameType), 2048 /* Late */) :
+ createSymbol(4 /* Property */ | member.flags, getPropertyNameFromType(nameType), 2048 /* Late */) :
createSymbol(4 /* Property */ | member.flags, member.escapedName);
if (nameType) {
prop.nameType = nameType;
@@ -48004,6 +48065,10 @@ var ts;
childrenPropSymbol.type = childrenTypes.length === 1 ?
childrenTypes[0] :
(getArrayLiteralTupleTypeIfApplicable(childrenTypes, childrenContextualType, /*hasRestElement*/ false) || createArrayType(getUnionType(childrenTypes)));
+ // Fake up a property declaration for the children
+ childrenPropSymbol.valueDeclaration = ts.createPropertySignature(/*modifiers*/ undefined, ts.unescapeLeadingUnderscores(jsxChildrenPropertyName), /*questionToken*/ undefined, /*type*/ undefined, /*initializer*/ undefined);
+ childrenPropSymbol.valueDeclaration.parent = attributes;
+ childrenPropSymbol.valueDeclaration.symbol = childrenPropSymbol;
var childPropMap = ts.createSymbolTable();
childPropMap.set(jsxChildrenPropertyName, childrenPropSymbol);
spread = getSpreadType(spread, createAnonymousType(attributes.symbol, childPropMap, ts.emptyArray, ts.emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined), attributes.symbol, typeFlags, objectFlags);
@@ -49683,6 +49748,12 @@ var ts;
if (inferenceContext) {
var typeArgumentTypes = inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext);
checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration));
+ // If the original signature has a generic rest type, instantiation may produce a
+ // signature with different arity and we need to perform another arity check.
+ if (getNonArrayRestType(candidate) && !hasCorrectArity(node, args, checkCandidate, signatureHelpTrailingComma)) {
+ candidateForArgumentArityError = checkCandidate;
+ continue;
+ }
}
if (!checkApplicableSignature(node, args, checkCandidate, relation, excludeArgument, /*reportErrors*/ false)) {
// Give preference to error candidates that have no rest parameters (as they are more specific)
@@ -50234,7 +50305,7 @@ var ts;
return true;
// If the symbol of the node has members, treat it like a constructor.
var symbol = getSymbolOfNode(func);
- return !!symbol && symbol.members !== undefined;
+ return !!symbol && (symbol.members !== undefined || symbol.exports !== undefined && symbol.exports.get("prototype") !== undefined);
}
return false;
}
@@ -50251,10 +50322,6 @@ var ts;
inferred = getInferredClassType(symbol);
}
var assigned = getAssignedClassType(symbol);
- var valueType = getTypeOfSymbol(symbol);
- if (valueType.symbol && !isInferredClassType(valueType) && isJSConstructor(valueType.symbol.valueDeclaration)) {
- inferred = getInferredClassType(valueType.symbol);
- }
return assigned && inferred ?
getIntersectionType([inferred, assigned]) :
assigned || inferred;
@@ -50289,11 +50356,6 @@ var ts;
}
return links.inferredClassType;
}
- function isInferredClassType(type) {
- return type.symbol
- && ts.getObjectFlags(type) & 16 /* Anonymous */
- && getSymbolLinks(type.symbol).inferredClassType === type;
- }
/**
* Syntactically and semantically checks a call or new expression.
* @param node The call/new expression to be checked.
@@ -50312,20 +50374,9 @@ var ts;
declaration.kind !== 157 /* Constructor */ &&
declaration.kind !== 161 /* ConstructSignature */ &&
declaration.kind !== 166 /* ConstructorType */ &&
- !ts.isJSDocConstructSignature(declaration)) {
- // When resolved signature is a call signature (and not a construct signature) the result type is any, unless
- // the declaring function had members created through 'x.prototype.y = expr' or 'this.y = expr' psuedodeclarations
- // in a JS file
- // Note:JS inferred classes might come from a variable declaration instead of a function declaration.
- // In this case, using getResolvedSymbol directly is required to avoid losing the members from the declaration.
- var funcSymbol = checkExpression(node.expression).symbol;
- if (!funcSymbol && node.expression.kind === 72 /* Identifier */) {
- funcSymbol = getResolvedSymbol(node.expression);
- }
- var type = funcSymbol && getJSClassType(funcSymbol);
- if (type) {
- return signature.target ? instantiateType(type, signature.mapper) : type;
- }
+ !ts.isJSDocConstructSignature(declaration) &&
+ !isJSConstructor(declaration)) {
+ // When resolved signature is a call signature (and not a construct signature) the result type is any
if (noImplicitAny) {
error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type);
}
@@ -51380,7 +51431,7 @@ var ts;
if (!(isTypeComparableTo(leftType, stringType) || isTypeAssignableToKind(leftType, 296 /* NumberLike */ | 12288 /* ESSymbolLike */))) {
error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol);
}
- if (!isTypeAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */)) {
+ if (!allTypesAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */)) {
error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
}
return booleanType;
@@ -51401,15 +51452,15 @@ var ts;
if (rightIsThis === void 0) { rightIsThis = false; }
if (property.kind === 275 /* PropertyAssignment */ || property.kind === 276 /* ShorthandPropertyAssignment */) {
var name = property.name;
- var text = ts.getTextOfPropertyName(name);
- if (text) {
+ var exprType = getLiteralTypeFromPropertyName(name);
+ if (isTypeUsableAsPropertyName(exprType)) {
+ var text = getPropertyNameFromType(exprType);
var prop = getPropertyOfType(objectLiteralType, text);
if (prop) {
markPropertyAsReferenced(prop, property, rightIsThis);
checkPropertyAccessibility(property, /*isSuper*/ false, objectLiteralType, prop);
}
}
- var exprType = getLiteralTypeFromPropertyName(name);
var elementType = getIndexedAccessType(objectLiteralType, exprType, name);
var type = getFlowTypeOfDestructuring(property, elementType);
return checkDestructuringAssignment(property.kind === 276 /* ShorthandPropertyAssignment */ ? property : property.initializer, type);
@@ -54399,10 +54450,11 @@ var ts;
var parent = node.parent.parent;
var parentType = getTypeForBindingElementParent(parent);
var name = node.propertyName || node.name;
- if (!ts.isBindingPattern(name)) {
- var nameText = ts.getTextOfPropertyName(name);
- if (nameText) {
- var property = getPropertyOfType(parentType, nameText); // TODO: GH#18217
+ if (!ts.isBindingPattern(name) && parentType) {
+ var exprType = getLiteralTypeFromPropertyName(name);
+ if (isTypeUsableAsPropertyName(exprType)) {
+ var nameText = getPropertyNameFromType(exprType);
+ var property = getPropertyOfType(parentType, nameText);
if (property) {
markPropertyAsReferenced(property, /*nodeForCheckWriteOnly*/ undefined, /*isThisAccess*/ false); // A destructuring is never a write-only reference.
checkPropertyAccessibility(parent, !!parent.initializer && parent.initializer.kind === 98 /* SuperKeyword */, parentType, property);
@@ -54759,7 +54811,7 @@ var ts;
? downlevelIteration
? ts.Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator
: isIterable
- ? ts.Diagnostics.Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators
+ ? ts.Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators
: ts.Diagnostics.Type_0_is_not_an_array_type
: downlevelIteration
? ts.Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator
@@ -59401,6 +59453,7 @@ var ts;
if (nodeArguments.length !== 1) {
return grammarErrorOnNode(node, ts.Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument);
}
+ checkGrammarForDisallowedTrailingComma(nodeArguments);
// see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import.
// parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import.
if (ts.isSpreadElement(nodeArguments[0])) {
@@ -61833,22 +61886,62 @@ var ts;
return node;
}
ts.createBundle = createBundle;
- function createUnparsedSourceFile(text, mapPath, map) {
+ function createUnparsedSourceFile(textOrInputFiles, mapPathOrType, map) {
var node = ts.createNode(281 /* UnparsedSource */);
- node.text = text;
- node.sourceMapPath = mapPath;
- node.sourceMapText = map;
+ if (!ts.isString(textOrInputFiles)) {
+ ts.Debug.assert(mapPathOrType === "js" || mapPathOrType === "dts");
+ node.fileName = mapPathOrType === "js" ? textOrInputFiles.javascriptPath : textOrInputFiles.declarationPath;
+ node.sourceMapPath = mapPathOrType === "js" ? textOrInputFiles.javascriptMapPath : textOrInputFiles.declarationMapPath;
+ Object.defineProperties(node, {
+ text: { get: function () { return mapPathOrType === "js" ? textOrInputFiles.javascriptText : textOrInputFiles.declarationText; } },
+ sourceMapText: { get: function () { return mapPathOrType === "js" ? textOrInputFiles.javascriptMapText : textOrInputFiles.declarationMapText; } },
+ });
+ }
+ else {
+ node.text = textOrInputFiles;
+ node.sourceMapPath = mapPathOrType;
+ node.sourceMapText = map;
+ }
return node;
}
ts.createUnparsedSourceFile = createUnparsedSourceFile;
- function createInputFiles(javascript, declaration, javascriptMapPath, javascriptMapText, declarationMapPath, declarationMapText) {
+ function createInputFiles(javascriptTextOrReadFileText, declarationTextOrJavascriptPath, javascriptMapPath, javascriptMapTextOrDeclarationPath, declarationMapPath, declarationMapText) {
var node = ts.createNode(282 /* InputFiles */);
- node.javascriptText = javascript;
- node.javascriptMapPath = javascriptMapPath;
- node.javascriptMapText = javascriptMapText;
- node.declarationText = declaration;
- node.declarationMapPath = declarationMapPath;
- node.declarationMapText = declarationMapText;
+ if (!ts.isString(javascriptTextOrReadFileText)) {
+ var cache_1 = ts.createMap();
+ var textGetter_1 = function (path) {
+ if (path === undefined)
+ return undefined;
+ var value = cache_1.get(path);
+ if (value === undefined) {
+ value = javascriptTextOrReadFileText(path);
+ cache_1.set(path, value !== undefined ? value : false);
+ }
+ return value !== false ? value : undefined;
+ };
+ var definedTextGetter_1 = function (path) {
+ var result = textGetter_1(path);
+ return result !== undefined ? result : "/* Input file " + path + " was missing */\r\n";
+ };
+ node.javascriptPath = declarationTextOrJavascriptPath;
+ node.javascriptMapPath = javascriptMapPath;
+ node.declarationPath = ts.Debug.assertDefined(javascriptMapTextOrDeclarationPath);
+ node.declarationMapPath = declarationMapPath;
+ Object.defineProperties(node, {
+ javascriptText: { get: function () { return definedTextGetter_1(declarationTextOrJavascriptPath); } },
+ javascriptMapText: { get: function () { return textGetter_1(javascriptMapPath); } },
+ declarationText: { get: function () { return definedTextGetter_1(ts.Debug.assertDefined(javascriptMapTextOrDeclarationPath)); } },
+ declarationMapText: { get: function () { return textGetter_1(declarationMapPath); } } // TODO:: if there is inline sourceMap in dtsFile, use that
+ });
+ }
+ else {
+ node.javascriptText = javascriptTextOrReadFileText;
+ node.javascriptMapPath = javascriptMapPath;
+ node.javascriptMapText = javascriptMapTextOrDeclarationPath;
+ node.declarationText = declarationTextOrJavascriptPath;
+ node.declarationMapPath = declarationMapPath;
+ node.declarationMapText = declarationMapText;
+ }
return node;
}
ts.createInputFiles = createInputFiles;
@@ -66199,7 +66292,7 @@ var ts;
function transformBundle(node) {
return ts.createBundle(node.sourceFiles.map(transformSourceFile), ts.mapDefined(node.prepends, function (prepend) {
if (prepend.kind === 282 /* InputFiles */) {
- return ts.createUnparsedSourceFile(prepend.javascriptText, prepend.javascriptMapPath, prepend.javascriptMapText);
+ return ts.createUnparsedSourceFile(prepend, "js");
}
return prepend;
}));
@@ -80432,7 +80525,7 @@ var ts;
return ts.updateSourceFileNode(sourceFile, transformAndReplaceLatePaintedStatements(updated), /*isDeclarationFile*/ true, /*referencedFiles*/ [], /*typeReferences*/ [], /*hasNoDefaultLib*/ false, /*libReferences*/ []);
}), ts.mapDefined(node.prepends, function (prepend) {
if (prepend.kind === 282 /* InputFiles */) {
- return ts.createUnparsedSourceFile(prepend.declarationText, prepend.declarationMapPath, prepend.declarationMapText);
+ return ts.createUnparsedSourceFile(prepend, "dts");
}
}));
bundle.syntheticFileReferences = [];
@@ -81793,16 +81886,21 @@ var ts;
}
ts.forEachEmittedFile = forEachEmittedFile;
/*@internal*/
+ function getOutputPathsForBundle(options, forceDtsPaths) {
+ var outPath = options.outFile || options.out;
+ var jsFilePath = options.emitDeclarationOnly ? undefined : outPath;
+ var sourceMapFilePath = jsFilePath && getSourceMapFilePath(jsFilePath, options);
+ var declarationFilePath = (forceDtsPaths || ts.getEmitDeclarations(options)) ? ts.removeFileExtension(outPath) + ".d.ts" /* Dts */ : undefined;
+ var declarationMapPath = declarationFilePath && ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
+ var bundleInfoPath = options.references && jsFilePath ? (ts.removeFileExtension(jsFilePath) + infoExtension) : undefined;
+ return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: bundleInfoPath };
+ }
+ ts.getOutputPathsForBundle = getOutputPathsForBundle;
+ /*@internal*/
function getOutputPathsFor(sourceFile, host, forceDtsPaths) {
var options = host.getCompilerOptions();
if (sourceFile.kind === 280 /* Bundle */) {
- var outPath = options.outFile || options.out;
- var jsFilePath = options.emitDeclarationOnly ? undefined : outPath;
- var sourceMapFilePath = jsFilePath && getSourceMapFilePath(jsFilePath, options);
- var declarationFilePath = (forceDtsPaths || ts.getEmitDeclarations(options)) ? ts.removeFileExtension(outPath) + ".d.ts" /* Dts */ : undefined;
- var declarationMapPath = declarationFilePath && ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
- var bundleInfoPath = options.references && jsFilePath ? (ts.removeFileExtension(jsFilePath) + infoExtension) : undefined;
- return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: bundleInfoPath };
+ return getOutputPathsForBundle(options, forceDtsPaths);
}
else {
var ownOutputFilePath = ts.getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options));
@@ -85597,10 +85695,10 @@ var ts;
}
}
/**
- * Skips trivia such as comments and white-space that can optionally overriden by the source map source
+ * Skips trivia such as comments and white-space that can be optionally overridden by the source-map source
*/
function skipSourceTrivia(source, pos) {
- return source.skipTrivia ? source.skipTrivia(pos) : ts.skipTrivia(sourceMapSource.text, pos);
+ return source.skipTrivia ? source.skipTrivia(pos) : ts.skipTrivia(source.text, pos);
}
/**
* Emits a mapping.
@@ -87271,14 +87369,12 @@ var ts;
// Upstream project didn't have outFile set -- skip (error will have been issued earlier)
if (!out)
continue;
- var dtsFilename = ts.changeExtension(out, ".d.ts");
- var js = host.readFile(out) || "/* Input file " + out + " was missing */\r\n";
- var jsMapPath = out + ".map"; // TODO: try to read sourceMappingUrl comment from the file
- var jsMap = host.readFile(jsMapPath);
- var dts = host.readFile(dtsFilename) || "/* Input file " + dtsFilename + " was missing */\r\n";
- var dtsMapPath = dtsFilename + ".map";
- var dtsMap = host.readFile(dtsMapPath);
- var node = ts.createInputFiles(js, dts, jsMap && jsMapPath, jsMap, dtsMap && dtsMapPath, dtsMap);
+ var _a = ts.getOutputPathsForBundle(resolvedRefOpts.options, /*forceDtsPaths*/ true), jsFilePath = _a.jsFilePath, sourceMapFilePath = _a.sourceMapFilePath, declarationFilePath = _a.declarationFilePath, declarationMapPath = _a.declarationMapPath;
+ var node = ts.createInputFiles(function (fileName) {
+ var path = toPath(fileName);
+ var sourceFile = getSourceFileByPath(path);
+ return sourceFile ? sourceFile.text : filesByName.has(path) ? undefined : host.readFile(path);
+ }, jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath);
nodes.push(node);
}
}
@@ -99982,6 +100078,11 @@ var ts;
}
return ts.createTextSpanFromBounds(start, end);
}
+ function getTextSpanOfEntry(entry) {
+ return entry.kind === 0 /* Span */ ? entry.textSpan :
+ getTextSpan(entry.node, entry.node.getSourceFile());
+ }
+ FindAllReferences.getTextSpanOfEntry = getTextSpanOfEntry;
/** A node is considered a writeAccess iff it is a name of a declaration or a target of an assignment */
function isWriteAccessForReference(node) {
var decl = ts.getDeclarationFromName(node);
@@ -100075,24 +100176,100 @@ var ts;
if (symbol.escapedName === "export=" /* ExportEquals */) {
return getReferencedSymbolsForModule(program, symbol.parent, /*excludeImportTypeOfExportEquals*/ false, sourceFiles, sourceFilesSet);
}
- var moduleReferences = ts.emptyArray;
- var moduleSourceFile = isModuleSymbol(symbol);
- var referencedNode = node;
- if (moduleSourceFile) {
- var exportEquals = symbol.exports.get("export=" /* ExportEquals */);
- // If !!exportEquals, we're about to add references to `import("mod")` anyway, so don't double-count them.
- moduleReferences = getReferencedSymbolsForModule(program, symbol, !!exportEquals, sourceFiles, sourceFilesSet);
- if (!exportEquals || !sourceFilesSet.has(moduleSourceFile.fileName))
- return moduleReferences;
- // Continue to get references to 'export ='.
- symbol = ts.skipAlias(exportEquals, checker);
- referencedNode = undefined;
- }
- return ts.concatenate(moduleReferences, getReferencedSymbolsForSymbol(symbol, referencedNode, sourceFiles, sourceFilesSet, checker, cancellationToken, options));
+ var moduleReferences = getReferencedSymbolsForModuleIfDeclaredBySourceFile(symbol, program, sourceFiles, cancellationToken, options, sourceFilesSet);
+ if (moduleReferences && !(symbol.flags & 33554432 /* Transient */)) {
+ return moduleReferences;
+ }
+ var aliasedSymbol = getMergedAliasedSymbolOfNamespaceExportDeclaration(node, symbol, checker);
+ var moduleReferencesOfExportTarget = aliasedSymbol &&
+ getReferencedSymbolsForModuleIfDeclaredBySourceFile(aliasedSymbol, program, sourceFiles, cancellationToken, options, sourceFilesSet);
+ var references = getReferencedSymbolsForSymbol(symbol, node, sourceFiles, sourceFilesSet, checker, cancellationToken, options);
+ return mergeReferences(program, moduleReferences, references, moduleReferencesOfExportTarget);
}
Core.getReferencedSymbolsForNode = getReferencedSymbolsForNode;
- function isModuleSymbol(symbol) {
- return symbol.flags & 1536 /* Module */ ? ts.find(symbol.declarations, ts.isSourceFile) : undefined;
+ function getMergedAliasedSymbolOfNamespaceExportDeclaration(node, symbol, checker) {
+ if (node.parent && ts.isNamespaceExportDeclaration(node.parent)) {
+ var aliasedSymbol = checker.getAliasedSymbol(symbol);
+ var targetSymbol = checker.getMergedSymbol(aliasedSymbol);
+ if (aliasedSymbol !== targetSymbol) {
+ return targetSymbol;
+ }
+ }
+ return undefined;
+ }
+ function getReferencedSymbolsForModuleIfDeclaredBySourceFile(symbol, program, sourceFiles, cancellationToken, options, sourceFilesSet) {
+ var moduleSourceFile = symbol.flags & 1536 /* Module */ ? ts.find(symbol.declarations, ts.isSourceFile) : undefined;
+ if (!moduleSourceFile)
+ return undefined;
+ var exportEquals = symbol.exports.get("export=" /* ExportEquals */);
+ // If !!exportEquals, we're about to add references to `import("mod")` anyway, so don't double-count them.
+ var moduleReferences = getReferencedSymbolsForModule(program, symbol, !!exportEquals, sourceFiles, sourceFilesSet);
+ if (!exportEquals || !sourceFilesSet.has(moduleSourceFile.fileName))
+ return moduleReferences;
+ // Continue to get references to 'export ='.
+ var checker = program.getTypeChecker();
+ symbol = ts.skipAlias(exportEquals, checker);
+ return mergeReferences(program, moduleReferences, getReferencedSymbolsForSymbol(symbol, /*node*/ undefined, sourceFiles, sourceFilesSet, checker, cancellationToken, options));
+ }
+ /**
+ * Merges the references by sorting them (by file index in sourceFiles and their location in it) that point to same definition symbol
+ */
+ function mergeReferences(program) {
+ var referencesToMerge = [];
+ for (var _i = 1; _i < arguments.length; _i++) {
+ referencesToMerge[_i - 1] = arguments[_i];
+ }
+ var result;
+ for (var _a = 0, referencesToMerge_1 = referencesToMerge; _a < referencesToMerge_1.length; _a++) {
+ var references = referencesToMerge_1[_a];
+ if (!references || !references.length)
+ continue;
+ if (!result) {
+ result = references;
+ continue;
+ }
+ var _loop_13 = function (entry) {
+ if (!entry.definition || entry.definition.type !== 0 /* Symbol */) {
+ result.push(entry);
+ return "continue";
+ }
+ var symbol = entry.definition.symbol;
+ var refIndex = ts.findIndex(result, function (ref) { return !!ref.definition &&
+ ref.definition.type === 0 /* Symbol */ &&
+ ref.definition.symbol === symbol; });
+ if (refIndex === -1) {
+ result.push(entry);
+ return "continue";
+ }
+ var reference = result[refIndex];
+ result[refIndex] = {
+ definition: reference.definition,
+ references: reference.references.concat(entry.references).sort(function (entry1, entry2) {
+ var entry1File = getSourceFileIndexOfEntry(program, entry1);
+ var entry2File = getSourceFileIndexOfEntry(program, entry2);
+ if (entry1File !== entry2File) {
+ return ts.compareValues(entry1File, entry2File);
+ }
+ var entry1Span = FindAllReferences.getTextSpanOfEntry(entry1);
+ var entry2Span = FindAllReferences.getTextSpanOfEntry(entry2);
+ return entry1Span.start !== entry2Span.start ?
+ ts.compareValues(entry1Span.start, entry2Span.start) :
+ ts.compareValues(entry1Span.length, entry2Span.length);
+ })
+ };
+ };
+ for (var _b = 0, references_1 = references; _b < references_1.length; _b++) {
+ var entry = references_1[_b];
+ _loop_13(entry);
+ }
+ }
+ return result;
+ }
+ function getSourceFileIndexOfEntry(program, entry) {
+ var sourceFile = entry.kind === 0 /* Span */ ?
+ program.getSourceFile(entry.fileName) :
+ entry.node.getSourceFile();
+ return program.getSourceFiles().indexOf(sourceFile);
}
function getReferencedSymbolsForModule(program, symbol, excludeImportTypeOfExportEquals, sourceFiles, sourceFilesSet) {
ts.Debug.assert(!!symbol.valueDeclaration);
@@ -100129,7 +100306,7 @@ var ts;
break;
default:
// This may be merged with something.
- ts.Debug.fail("Expected a module symbol to be declared by a SourceFile or ModuleDeclaration.");
+ ts.Debug.assert(!!(symbol.flags & 33554432 /* Transient */), "Expected a module symbol to be declared by a SourceFile or ModuleDeclaration.");
}
}
var exported = symbol.exports.get("export=" /* ExportEquals */);
@@ -100232,6 +100409,9 @@ var ts;
// If the symbol is declared as part of a declaration like `{ type: "a" } | { type: "b" }`, use the property on the union type to get more references.
return ts.firstDefined(symbol.declarations, function (decl) {
if (!decl.parent) {
+ // Ignore UMD module and global merge
+ if (symbol.flags & 33554432 /* Transient */)
+ return undefined;
// Assertions for GH#21814. We should be handling SourceFile symbols in `getReferencedSymbolsForModule` instead of getting here.
ts.Debug.fail("Unexpected symbol at " + ts.Debug.showSyntaxKind(node) + ": " + ts.Debug.showSymbol(symbol));
}
@@ -100246,6 +100426,12 @@ var ts;
SpecialSearchKind[SpecialSearchKind["Constructor"] = 1] = "Constructor";
SpecialSearchKind[SpecialSearchKind["Class"] = 2] = "Class";
})(SpecialSearchKind || (SpecialSearchKind = {}));
+ function getNonModuleSymbolOfMergedModuleSymbol(symbol) {
+ if (!(symbol.flags & (1536 /* Module */ | 33554432 /* Transient */)))
+ return undefined;
+ var decl = symbol.declarations && ts.find(symbol.declarations, function (d) { return !ts.isSourceFile(d) && !ts.isModuleDeclaration(d); });
+ return decl && decl.symbol;
+ }
/**
* Holds all state needed for the finding references.
* Unlike `Search`, there is only one `State`.
@@ -100304,7 +100490,7 @@ var ts;
// Note: getLocalSymbolForExportDefault handles `export default class C {}`, but not `export default C` or `export { C as default }`.
// The other two forms seem to be handled downstream (e.g. in `skipPastExportOrImportSpecifier`), so special-casing the first form
// here appears to be intentional).
- var _a = searchOptions.text, text = _a === void 0 ? ts.stripQuotes(ts.unescapeLeadingUnderscores((ts.getLocalSymbolForExportDefault(symbol) || symbol).escapedName)) : _a, _b = searchOptions.allSearchSymbols, allSearchSymbols = _b === void 0 ? [symbol] : _b;
+ var _a = searchOptions.text, text = _a === void 0 ? ts.stripQuotes(ts.unescapeLeadingUnderscores((ts.getLocalSymbolForExportDefault(symbol) || getNonModuleSymbolOfMergedModuleSymbol(symbol) || symbol).escapedName)) : _a, _b = searchOptions.allSearchSymbols, allSearchSymbols = _b === void 0 ? [symbol] : _b;
var escapedText = ts.escapeLeadingUnderscores(text);
var parents = this.options.implementations && location ? getParentSymbolsOfPropertyAccess(location, symbol, this.checker) : undefined;
return { symbol: symbol, comingFrom: comingFrom, text: text, escapedText: escapedText, parents: parents, allSearchSymbols: allSearchSymbols, includes: function (sym) { return ts.contains(allSearchSymbols, sym); } };
@@ -101140,6 +101326,13 @@ var ts;
if (res2)
return res2;
}
+ var aliasedSymbol = getMergedAliasedSymbolOfNamespaceExportDeclaration(location, symbol, checker);
+ if (aliasedSymbol) {
+ // In case of UMD module and global merging, search for global as well
+ var res_2 = cbSymbol(aliasedSymbol, /*rootSymbol*/ undefined, /*baseSymbol*/ undefined, 1 /* Node */);
+ if (res_2)
+ return res_2;
+ }
var res = fromRoot(symbol);
if (res)
return res;
@@ -101236,7 +101429,8 @@ var ts;
Core.getIntersectingMeaningFromDeclarations = getIntersectingMeaningFromDeclarations;
function isImplementation(node) {
return !!(node.flags & 4194304 /* Ambient */)
- || (ts.isVariableLike(node) ? ts.hasInitializer(node)
+ ? !(ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node))
+ : (ts.isVariableLike(node) ? ts.hasInitializer(node)
: ts.isFunctionLikeDeclaration(node) ? !!node.body
: ts.isClassLike(node) || ts.isModuleOrEnumDeclaration(node));
}
@@ -101394,7 +101588,7 @@ var ts;
}
function updateImports(program, changeTracker, oldToNew, newToOld, host, getCanonicalFileName) {
var allFiles = program.getSourceFiles();
- var _loop_13 = function (sourceFile) {
+ var _loop_14 = function (sourceFile) {
var newFromOld = oldToNew(sourceFile.path);
var newImportFromPath = newFromOld !== undefined ? newFromOld : sourceFile.path;
var newImportFromDirectory = ts.getDirectoryPath(newImportFromPath);
@@ -101426,7 +101620,7 @@ var ts;
};
for (var _i = 0, allFiles_1 = allFiles; _i < allFiles_1.length; _i++) {
var sourceFile = allFiles_1[_i];
- _loop_13(sourceFile);
+ _loop_14(sourceFile);
}
}
function combineNormal(pathA, pathB) {
@@ -102216,7 +102410,7 @@ var ts;
if (!patternMatcher)
return ts.emptyArray;
var rawItems = [];
- var _loop_14 = function (sourceFile) {
+ var _loop_15 = function (sourceFile) {
cancellationToken.throwIfCancellationRequested();
if (excludeDtsFiles && sourceFile.isDeclarationFile) {
return "continue";
@@ -102228,7 +102422,7 @@ var ts;
// Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[]
for (var _i = 0, sourceFiles_6 = sourceFiles; _i < sourceFiles_6.length; _i++) {
var sourceFile = sourceFiles_6[_i];
- _loop_14(sourceFile);
+ _loop_15(sourceFile);
}
rawItems.sort(compareNavigateToItems);
return (maxResultCount === undefined ? rawItems : rawItems.slice(0, maxResultCount)).map(createNavigateToItem);
@@ -103756,13 +103950,13 @@ var ts;
// Assumes 'value' is already lowercase.
function indexOfIgnoringCase(str, value) {
var n = str.length - value.length;
- var _loop_15 = function (start) {
+ var _loop_16 = function (start) {
if (every(value, function (valueChar, i) { return toLowerCase(str.charCodeAt(i + start)) === valueChar; })) {
return { value: start };
}
};
for (var start = 0; start <= n; start++) {
- var state_4 = _loop_15(start);
+ var state_4 = _loop_16(start);
if (typeof state_4 === "object")
return state_4.value;
}
@@ -104775,7 +104969,7 @@ var ts;
return ts.createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart);
}
function getContainingArgumentInfo(node, position, sourceFile, checker, isManuallyInvoked) {
- var _loop_16 = function (n) {
+ var _loop_17 = function (n) {
// If the node is not a subspan of its parent, this is a big problem.
// There have been crashes that might be caused by this violation.
ts.Debug.assert(ts.rangeContainsRange(n.parent, n), "Not a subspan", function () { return "Child: " + ts.Debug.showSyntaxKind(n) + ", parent: " + ts.Debug.showSyntaxKind(n.parent); });
@@ -104784,8 +104978,8 @@ var ts;
return { value: argumentInfo };
}
};
- for (var n = node; isManuallyInvoked || (!ts.isBlock(n) && !ts.isSourceFile(n)); n = n.parent) {
- var state_5 = _loop_16(n);
+ for (var n = node; !ts.isSourceFile(n) && (isManuallyInvoked || !ts.isBlock(n)); n = n.parent) {
+ var state_5 = _loop_17(n);
if (typeof state_5 === "object")
return state_5.value;
}
@@ -105942,7 +106136,7 @@ var ts;
return typeof o.type === "object" && !ts.forEachEntry(o.type, function (v) { return typeof v !== "number"; });
});
options = ts.cloneCompilerOptions(options);
- var _loop_17 = function (opt) {
+ var _loop_18 = function (opt) {
if (!ts.hasProperty(options, opt.name)) {
return "continue";
}
@@ -105961,7 +106155,7 @@ var ts;
};
for (var _i = 0, commandLineOptionsStringToEnum_1 = commandLineOptionsStringToEnum; _i < commandLineOptionsStringToEnum_1.length; _i++) {
var opt = commandLineOptionsStringToEnum_1[_i];
- _loop_17(opt);
+ _loop_18(opt);
}
return options;
}
@@ -109133,7 +109327,7 @@ var ts;
ChangeTracker.prototype.finishDeleteDeclarations = function () {
var _this = this;
var deletedNodesInLists = new ts.NodeSet(); // Stores nodes in lists that we already deleted. Used to avoid deleting `, ` twice in `a, b`.
- var _loop_18 = function (sourceFile, node) {
+ var _loop_19 = function (sourceFile, node) {
if (!this_1.deletedNodes.some(function (d) { return d.sourceFile === sourceFile && ts.rangeContainsRangeExclusive(d.node, node); })) {
if (ts.isArray(node)) {
this_1.deleteRange(sourceFile, ts.rangeOfTypeParameters(node));
@@ -109146,7 +109340,7 @@ var ts;
var this_1 = this;
for (var _i = 0, _a = this.deletedNodes; _i < _a.length; _i++) {
var _b = _a[_i], sourceFile = _b.sourceFile, node = _b.node;
- _loop_18(sourceFile, node);
+ _loop_19(sourceFile, node);
}
deletedNodesInLists.forEach(function (node) {
var sourceFile = node.getSourceFile();
@@ -109203,14 +109397,14 @@ var ts;
// order changes by start position
// If the start position is the same, put the shorter range first, since an empty range (x, x) may precede (x, y) but not vice-versa.
var normalized = ts.stableSort(changesInFile, function (a, b) { return (a.range.pos - b.range.pos) || (a.range.end - b.range.end); });
- var _loop_19 = function (i) {
+ var _loop_20 = function (i) {
ts.Debug.assert(normalized[i].range.end <= normalized[i + 1].range.pos, "Changes overlap", function () {
return JSON.stringify(normalized[i].range) + " and " + JSON.stringify(normalized[i + 1].range);
});
};
// verify that change intervals do not overlap, except possibly at end points.
for (var i = 0; i < normalized.length - 1; i++) {
- _loop_19(i);
+ _loop_20(i);
}
var textChanges = normalized.map(function (c) {
return ts.createTextChange(ts.createTextSpanFromRange(c.range), computeNewText(c, sourceFile, newLineCharacter, formatContext, validate));
@@ -110340,8 +110534,8 @@ var ts;
(function (InferFromReference) {
function inferTypesFromReferences(references, checker, cancellationToken) {
var usageContext = {};
- for (var _i = 0, references_1 = references; _i < references_1.length; _i++) {
- var reference = references_1[_i];
+ for (var _i = 0, references_2 = references; _i < references_2.length; _i++) {
+ var reference = references_2[_i];
cancellationToken.throwIfCancellationRequested();
inferTypeFromContext(reference, checker, usageContext);
}
@@ -110357,8 +110551,8 @@ var ts;
return undefined;
}
var usageContext = {};
- for (var _i = 0, references_2 = references; _i < references_2.length; _i++) {
- var reference = references_2[_i];
+ for (var _i = 0, references_3 = references; _i < references_3.length; _i++) {
+ var reference = references_3[_i];
cancellationToken.throwIfCancellationRequested();
inferTypeFromContext(reference, checker, usageContext);
}
@@ -110998,7 +111192,7 @@ var ts;
var newNodes = transformExpression(node, transformer, node);
changes.replaceNodeWithNodes(sourceFile, nodeToReplace, newNodes);
}
- var _loop_20 = function (statement) {
+ var _loop_21 = function (statement) {
ts.forEachChild(statement, function visit(node) {
if (ts.isCallExpression(node)) {
startTransformation(node, statement);
@@ -111010,7 +111204,7 @@ var ts;
};
for (var _i = 0, returnStatements_1 = returnStatements; _i < returnStatements_1.length; _i++) {
var statement = returnStatements_1[_i];
- _loop_20(statement);
+ _loop_21(statement);
}
}
function getReturnStatementsWithPromiseHandlers(body) {
@@ -112662,7 +112856,7 @@ var ts;
});
typeDeclToMembers.forEach(function (infos, classDeclaration) {
var supers = getAllSupers(classDeclaration, checker);
- var _loop_21 = function (info) {
+ var _loop_22 = function (info) {
// If some superclass added this property, don't add it again.
if (supers.some(function (superClassOrInterface) {
var superInfos = typeDeclToMembers.get(superClassOrInterface);
@@ -112689,7 +112883,7 @@ var ts;
};
for (var _i = 0, infos_1 = infos; _i < infos_1.length; _i++) {
var info = infos_1[_i];
- _loop_21(info);
+ _loop_22(info);
}
});
}));
@@ -113183,6 +113377,32 @@ var ts;
})(ts || (ts = {}));
/* @internal */
var ts;
+(function (ts) {
+ var codefix;
+ (function (codefix) {
+ var fixId = "enableExperimentalDecorators";
+ var errorCodes = [
+ ts.Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_to_remove_this_warning.code
+ ];
+ codefix.registerCodeFix({
+ errorCodes: errorCodes,
+ getCodeActions: function (context) {
+ var configFile = context.program.getCompilerOptions().configFile;
+ if (configFile === undefined) {
+ return undefined;
+ }
+ var changes = ts.textChanges.ChangeTracker.with(context, function (changeTracker) { return makeChange(changeTracker, configFile); });
+ return [codefix.createCodeFixActionNoFixId(fixId, changes, ts.Diagnostics.Enable_the_experimentalDecorators_option_in_your_configuration_file)];
+ },
+ fixIds: [fixId],
+ });
+ function makeChange(changeTracker, configFile) {
+ codefix.setJsonCompilerOptionValue(changeTracker, configFile, "experimentalDecorators", ts.createTrue());
+ }
+ })(codefix = ts.codefix || (ts.codefix = {}));
+})(ts || (ts = {}));
+/* @internal */
+var ts;
(function (ts) {
var codefix;
(function (codefix) {
@@ -114937,7 +115157,7 @@ var ts;
});
var namespaceImportName = namespaceNameConflicts ? ts.getUniqueName(preferredName, sourceFile) : preferredName;
var neededNamedImports = [];
- var _loop_22 = function (element) {
+ var _loop_23 = function (element) {
var propertyName = (element.propertyName || element.name).text;
ts.FindAllReferences.Core.eachSymbolReferenceInFile(element.name, checker, sourceFile, function (id) {
var access = ts.createPropertyAccess(ts.createIdentifier(namespaceImportName), propertyName);
@@ -114956,7 +115176,7 @@ var ts;
};
for (var _i = 0, _a = toConvert.elements; _i < _a.length; _i++) {
var element = _a[_i];
- _loop_22(element);
+ _loop_23(element);
}
changes.replaceNode(sourceFile, toConvert, ts.createNamespaceImport(ts.createIdentifier(namespaceImportName)));
if (neededNamedImports.length) {
@@ -116186,7 +116406,7 @@ var ts;
: ts.getEnclosingBlockScopeContainer(scopes[0]);
ts.forEachChild(containingLexicalScopeOfExtraction, checkForUsedDeclarations);
}
- var _loop_23 = function (i) {
+ var _loop_24 = function (i) {
var scopeUsages = usagesPerScope[i];
// Special case: in the innermost scope, all usages are available.
// (The computed value reflects the value at the top-level of the scope, but the
@@ -116226,7 +116446,7 @@ var ts;
}
};
for (var i = 0; i < scopes.length; i++) {
- _loop_23(i);
+ _loop_24(i);
}
return { target: target, usagesPerScope: usagesPerScope, functionErrorsPerScope: functionErrorsPerScope, constantErrorsPerScope: constantErrorsPerScope, exposedVariableDeclarations: exposedVariableDeclarations };
function isInGenericContext(node) {
@@ -116777,10 +116997,10 @@ var ts;
}
function updateImportsInOtherFiles(changes, program, oldFile, movedSymbols, newModuleName) {
var checker = program.getTypeChecker();
- var _loop_24 = function (sourceFile) {
+ var _loop_25 = function (sourceFile) {
if (sourceFile === oldFile)
return "continue";
- var _loop_25 = function (statement) {
+ var _loop_26 = function (statement) {
forEachImportInStatement(statement, function (importNode) {
if (checker.getSymbolAtLocation(moduleSpecifierFromImport(importNode)) !== oldFile.symbol)
return;
@@ -116802,12 +117022,12 @@ var ts;
};
for (var _i = 0, _a = sourceFile.statements; _i < _a.length; _i++) {
var statement = _a[_i];
- _loop_25(statement);
+ _loop_26(statement);
}
};
for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) {
var sourceFile = _a[_i];
- _loop_24(sourceFile);
+ _loop_25(sourceFile);
}
}
function getNamespaceLikeImport(node) {
@@ -117050,6 +117270,11 @@ var ts;
var movedSymbols = new SymbolSet();
var oldImportsNeededByNewFile = new SymbolSet();
var newFileImportsFromOldFile = new SymbolSet();
+ var containsJsx = ts.find(toMove, function (statement) { return !!(statement.transformFlags & 4 /* ContainsJsx */); });
+ var jsxNamespaceSymbol = getJsxNamespaceSymbol(containsJsx);
+ if (jsxNamespaceSymbol) { // Might not exist (e.g. in non-compiling code)
+ oldImportsNeededByNewFile.add(jsxNamespaceSymbol);
+ }
for (var _i = 0, toMove_1 = toMove; _i < toMove_1.length; _i++) {
var statement = toMove_1[_i];
forEachTopLevelDeclaration(statement, function (decl) {
@@ -117078,6 +117303,10 @@ var ts;
var statement = _c[_b];
if (ts.contains(toMove, statement))
continue;
+ // jsxNamespaceSymbol will only be set iff it is in oldImportsNeededByNewFile.
+ if (jsxNamespaceSymbol && !!(statement.transformFlags & 4 /* ContainsJsx */)) {
+ unusedImportsFromOldFile.delete(jsxNamespaceSymbol);
+ }
forEachReference(statement, checker, function (symbol) {
if (movedSymbols.has(symbol))
oldFileImportsFromNewFile.add(symbol);
@@ -117085,6 +117314,19 @@ var ts;
});
}
return { movedSymbols: movedSymbols, newFileImportsFromOldFile: newFileImportsFromOldFile, oldFileImportsFromNewFile: oldFileImportsFromNewFile, oldImportsNeededByNewFile: oldImportsNeededByNewFile, unusedImportsFromOldFile: unusedImportsFromOldFile };
+ function getJsxNamespaceSymbol(containsJsx) {
+ if (containsJsx === undefined) {
+ return undefined;
+ }
+ var jsxNamespace = checker.getJsxNamespace(containsJsx);
+ // Strictly speaking, this could resolve to a symbol other than the JSX namespace.
+ // This will produce erroneous output (probably, an incorrectly copied import) but
+ // is expected to be very rare and easily reversible.
+ var jsxNamespaceSymbol = checker.resolveName(jsxNamespace, containsJsx, 1920 /* Namespace */, /*excludeGlobals*/ true);
+ return !!jsxNamespaceSymbol && ts.some(jsxNamespaceSymbol.declarations, isInImport)
+ ? jsxNamespaceSymbol
+ : undefined;
+ }
}
// Below should all be utilities
function isInImport(decl) {
@@ -117103,7 +117345,7 @@ var ts;
}
function isVariableDeclarationInImport(decl) {
return ts.isSourceFile(decl.parent.parent.parent) &&
- decl.initializer && ts.isRequireCall(decl.initializer, /*checkArgumentIsStringLiteralLike*/ true);
+ !!decl.initializer && ts.isRequireCall(decl.initializer, /*checkArgumentIsStringLiteralLike*/ true);
}
function filterImport(i, moduleSpecifier, keep) {
switch (i.kind) {
@@ -122592,7 +122834,7 @@ var ts;
// ../../.. to walk from X/node_modules/typescript/lib/tsserver.js to X/node_modules/
var searchPaths = [ts.combinePaths(this.projectService.getExecutingFilePath(), "../../..")].concat(this.projectService.pluginProbeLocations);
if (this.projectService.globalPlugins) {
- var _loop_26 = function (globalPluginName) {
+ var _loop_27 = function (globalPluginName) {
// Skip empty names from odd commandline parses
if (!globalPluginName)
return "continue";
@@ -122607,7 +122849,7 @@ var ts;
// Enable global plugins with synthetic configuration entries
for (var _i = 0, _a = this.projectService.globalPlugins; _i < _a.length; _i++) {
var globalPluginName = _a[_i];
- _loop_26(globalPluginName);
+ _loop_27(globalPluginName);
}
}
};
@@ -123791,7 +124033,7 @@ var ts;
}
project.updateGraph();
if (!this.useSingleInferredProject && !project.projectRootPath) {
- var _loop_27 = function (inferredProject) {
+ var _loop_28 = function (inferredProject) {
if (inferredProject === project || inferredProject.isOrphan()) {
return "continue";
}
@@ -123812,7 +124054,7 @@ var ts;
// Note that we need to create a copy of the array since the list of project can change
for (var _i = 0, _a = this.inferredProjects; _i < _a.length; _i++) {
var inferredProject = _a[_i];
- _loop_27(inferredProject);
+ _loop_28(inferredProject);
}
}
return project;
@@ -124583,7 +124825,7 @@ var ts;
return projects;
function combineProjects(toAddInfo) {
if (toAddInfo !== info) {
- var _loop_28 = function (project) {
+ var _loop_29 = function (project) {
// Add the projects only if they can use symLink targets and not already in the list
if (project.languageServiceEnabled &&
!project.isOrphan() &&
@@ -124600,7 +124842,7 @@ var ts;
};
for (var _i = 0, _a = toAddInfo.containingProjects; _i < _a.length; _i++) {
var project = _a[_i];
- _loop_28(project);
+ _loop_29(project);
}
}
}
@@ -125270,13 +125512,13 @@ var ts;
this.printProjects();
};
ProjectService.prototype.collectChanges = function (lastKnownProjectVersions, currentProjects, result) {
- var _loop_29 = function (proj) {
+ var _loop_30 = function (proj) {
var knownProject = ts.find(lastKnownProjectVersions, function (p) { return p.projectName === proj.getProjectName(); });
result.push(proj.getChangesSinceVersion(knownProject && knownProject.version));
};
for (var _i = 0, currentProjects_1 = currentProjects; _i < currentProjects_1.length; _i++) {
var proj = currentProjects_1[_i];
- _loop_29(proj);
+ _loop_30(proj);
}
};
/* @internal */
@@ -125386,7 +125628,7 @@ var ts;
var excludeRules = [];
var normalizedNames = rootFiles.map(function (f) { return ts.normalizeSlashes(f.fileName); });
var excludedFiles = [];
- var _loop_30 = function (name) {
+ var _loop_31 = function (name) {
var rule = this_3.safelist[name];
for (var _i = 0, normalizedNames_1 = normalizedNames; _i < normalizedNames_1.length; _i++) {
var root = normalizedNames_1[_i];
@@ -125404,7 +125646,7 @@ var ts;
}
}
if (rule.exclude) {
- var _loop_32 = function (exclude) {
+ var _loop_33 = function (exclude) {
var processedRule = root.replace(rule.match, function () {
var groups = [];
for (var _i = 0; _i < arguments.length; _i++) {
@@ -125431,7 +125673,7 @@ var ts;
};
for (var _c = 0, _d = rule.exclude; _c < _d.length; _c++) {
var exclude = _d[_c];
- _loop_32(exclude);
+ _loop_33(exclude);
}
}
else {
@@ -125447,11 +125689,11 @@ var ts;
var this_3 = this;
for (var _i = 0, _a = Object.keys(this.safelist); _i < _a.length; _i++) {
var name = _a[_i];
- _loop_30(name);
+ _loop_31(name);
}
var excludeRegexes = excludeRules.map(function (e) { return new RegExp(e, "i"); });
var filesToKeep = [];
- var _loop_31 = function (i) {
+ var _loop_32 = function (i) {
if (excludeRegexes.some(function (re) { return re.test(normalizedNames[i]); })) {
excludedFiles.push(normalizedNames[i]);
}
@@ -125489,7 +125731,7 @@ var ts;
};
var this_4 = this;
for (var i = 0; i < proj.rootFiles.length; i++) {
- _loop_31(i);
+ _loop_32(i);
}
proj.rootFiles = filesToKeep;
return excludedFiles;
@@ -125894,7 +126136,7 @@ var ts;
var outputs = [];
combineProjectOutputWorker(projects, defaultProject, initialLocation, function (_a, getMappedLocation) {
var project = _a.project, location = _a.location;
- var _loop_33 = function (outputReferencedSymbol) {
+ var _loop_34 = function (outputReferencedSymbol) {
var mappedDefinitionFile = getMappedLocation(project, documentSpanLocation(outputReferencedSymbol.definition));
var definition = mappedDefinitionFile === undefined ? outputReferencedSymbol.definition : __assign({}, outputReferencedSymbol.definition, { textSpan: ts.createTextSpan(mappedDefinitionFile.pos, outputReferencedSymbol.definition.textSpan.length), fileName: mappedDefinitionFile.fileName });
var symbolToAddTo = ts.find(outputs, function (o) { return ts.documentSpansEqual(o.definition, definition); });
@@ -125912,7 +126154,7 @@ var ts;
};
for (var _i = 0, _b = project.getLanguageService().findReferences(location.fileName, location.pos) || server.emptyArray; _i < _b.length; _i++) {
var outputReferencedSymbol = _b[_i];
- _loop_33(outputReferencedSymbol);
+ _loop_34(outputReferencedSymbol);
}
}, function () { return getDefinitionLocation(defaultProject, initialLocation); });
return outputs.filter(function (o) { return o.references.length !== 0; });
diff --git a/lib/typescript.d.ts b/lib/typescript.d.ts
index 03f24988ed355..a7dd2892a238c 100644
--- a/lib/typescript.d.ts
+++ b/lib/typescript.d.ts
@@ -1726,15 +1726,18 @@ declare namespace ts {
}
interface InputFiles extends Node {
kind: SyntaxKind.InputFiles;
+ javascriptPath?: string;
javascriptText: string;
javascriptMapPath?: string;
javascriptMapText?: string;
+ declarationPath?: string;
declarationText: string;
declarationMapPath?: string;
declarationMapText?: string;
}
interface UnparsedSource extends Node {
kind: SyntaxKind.UnparsedSource;
+ fileName?: string;
text: string;
sourceMapPath?: string;
sourceMapText?: string;
@@ -2214,6 +2217,7 @@ declare namespace ts {
}
interface UniqueESSymbolType extends Type {
symbol: Symbol;
+ escapedName: __String;
}
interface StringLiteralType extends LiteralType {
value: string;
@@ -3097,6 +3101,7 @@ declare namespace ts {
scanJsxIdentifier(): SyntaxKind;
scanJsxAttributeValue(): SyntaxKind;
reScanJsxToken(): JsxTokenSyntaxKind;
+ reScanLessThanToken(): SyntaxKind;
scanJsxToken(): JsxTokenSyntaxKind;
scanJSDocToken(): JsDocSyntaxKind;
scan(): SyntaxKind;
@@ -3978,9 +3983,11 @@ declare namespace ts {
function updateCommaList(node: CommaListExpression, elements: ReadonlyArray): CommaListExpression;
function createBundle(sourceFiles: ReadonlyArray, prepends?: ReadonlyArray): Bundle;
function createUnparsedSourceFile(text: string): UnparsedSource;
+ function createUnparsedSourceFile(inputFile: InputFiles, type: "js" | "dts"): UnparsedSource;
function createUnparsedSourceFile(text: string, mapPath: string | undefined, map: string | undefined): UnparsedSource;
- function createInputFiles(javascript: string, declaration: string): InputFiles;
- function createInputFiles(javascript: string, declaration: string, javascriptMapPath: string | undefined, javascriptMapText: string | undefined, declarationMapPath: string | undefined, declarationMapText: string | undefined): InputFiles;
+ function createInputFiles(javascriptText: string, declarationText: string): InputFiles;
+ function createInputFiles(readFileText: (path: string) => string | undefined, javascriptPath: string, javascriptMapPath: string | undefined, declarationPath: string, declarationMapPath: string | undefined): InputFiles;
+ function createInputFiles(javascriptText: string, declarationText: string, javascriptMapPath: string | undefined, javascriptMapText: string | undefined, declarationMapPath: string | undefined, declarationMapText: string | undefined): InputFiles;
function updateBundle(node: Bundle, sourceFiles: ReadonlyArray, prepends?: ReadonlyArray): Bundle;
function createImmediatelyInvokedFunctionExpression(statements: ReadonlyArray): CallExpression;
function createImmediatelyInvokedFunctionExpression(statements: ReadonlyArray, param: ParameterDeclaration, paramValue: Expression): CallExpression;
diff --git a/lib/typescript.js b/lib/typescript.js
index 456bf6e54ec06..149e147ccb0b5 100644
--- a/lib/typescript.js
+++ b/lib/typescript.js
@@ -75,7 +75,7 @@ var ts;
// If changing the text in this section, be sure to test `configureNightly` too.
ts.versionMajorMinor = "3.3";
/** The version of the TypeScript compiler release */
- ts.version = ts.versionMajorMinor + ".0-rc";
+ ts.version = ts.versionMajorMinor + ".1";
})(ts || (ts = {}));
(function (ts) {
/* @internal */
@@ -5520,7 +5520,6 @@ var ts;
Property_0_is_used_before_being_assigned: diag(2565, ts.DiagnosticCategory.Error, "Property_0_is_used_before_being_assigned_2565", "Property '{0}' is used before being assigned."),
A_rest_element_cannot_have_a_property_name: diag(2566, ts.DiagnosticCategory.Error, "A_rest_element_cannot_have_a_property_name_2566", "A rest element cannot have a property name."),
Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations: diag(2567, ts.DiagnosticCategory.Error, "Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations_2567", "Enum declarations can only merge with namespace or other enum declarations."),
- Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators: diag(2568, ts.DiagnosticCategory.Error, "Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators_2568", "Type '{0}' is not an array type. Use compiler option '--downlevelIteration' to allow iterating of iterators."),
Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators: diag(2569, ts.DiagnosticCategory.Error, "Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterati_2569", "Type '{0}' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators."),
Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await: diag(2570, ts.DiagnosticCategory.Error, "Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await_2570", "Property '{0}' does not exist on type '{1}'. Did you forget to use 'await'?"),
Object_is_of_type_unknown: diag(2571, ts.DiagnosticCategory.Error, "Object_is_of_type_unknown_2571", "Object is of type 'unknown'."),
@@ -5615,7 +5614,7 @@ var ts;
Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor: diag(2715, ts.DiagnosticCategory.Error, "Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor_2715", "Abstract property '{0}' in class '{1}' cannot be accessed in the constructor."),
Type_parameter_0_has_a_circular_default: diag(2716, ts.DiagnosticCategory.Error, "Type_parameter_0_has_a_circular_default_2716", "Type parameter '{0}' has a circular default."),
Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_type_2: diag(2717, ts.DiagnosticCategory.Error, "Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_t_2717", "Subsequent property declarations must have the same type. Property '{0}' must be of type '{1}', but here has type '{2}'."),
- Duplicate_declaration_0: diag(2718, ts.DiagnosticCategory.Error, "Duplicate_declaration_0_2718", "Duplicate declaration '{0}'."),
+ Duplicate_property_0: diag(2718, ts.DiagnosticCategory.Error, "Duplicate_property_0_2718", "Duplicate property '{0}'."),
Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated: diag(2719, ts.DiagnosticCategory.Error, "Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated_2719", "Type '{0}' is not assignable to type '{1}'. Two different types with this name exist, but they are unrelated."),
Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass: diag(2720, ts.DiagnosticCategory.Error, "Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclas_2720", "Class '{0}' incorrectly implements class '{1}'. Did you mean to extend '{1}' and inherit its members as a subclass?"),
Cannot_invoke_an_object_which_is_possibly_null: diag(2721, ts.DiagnosticCategory.Error, "Cannot_invoke_an_object_which_is_possibly_null_2721", "Cannot invoke an object which is possibly 'null'."),
@@ -5630,6 +5629,7 @@ var ts;
An_arrow_function_cannot_have_a_this_parameter: diag(2730, ts.DiagnosticCategory.Error, "An_arrow_function_cannot_have_a_this_parameter_2730", "An arrow function cannot have a 'this' parameter."),
Implicit_conversion_of_a_symbol_to_a_string_will_fail_at_runtime_Consider_wrapping_this_expression_in_String: diag(2731, ts.DiagnosticCategory.Error, "Implicit_conversion_of_a_symbol_to_a_string_will_fail_at_runtime_Consider_wrapping_this_expression_i_2731", "Implicit conversion of a 'symbol' to a 'string' will fail at runtime. Consider wrapping this expression in 'String(...)'."),
Cannot_find_module_0_Consider_using_resolveJsonModule_to_import_module_with_json_extension: diag(2732, ts.DiagnosticCategory.Error, "Cannot_find_module_0_Consider_using_resolveJsonModule_to_import_module_with_json_extension_2732", "Cannot find module '{0}'. Consider using '--resolveJsonModule' to import module with '.json' extension"),
+ Property_0_was_also_declared_here: diag(2733, ts.DiagnosticCategory.Error, "Property_0_was_also_declared_here_2733", "Property '{0}' was also declared here."),
It_is_highly_likely_that_you_are_missing_a_semicolon: diag(2734, ts.DiagnosticCategory.Error, "It_is_highly_likely_that_you_are_missing_a_semicolon_2734", "It is highly likely that you are missing a semicolon."),
Did_you_mean_for_0_to_be_constrained_to_type_new_args_Colon_any_1: diag(2735, ts.DiagnosticCategory.Error, "Did_you_mean_for_0_to_be_constrained_to_type_new_args_Colon_any_1_2735", "Did you mean for '{0}' to be constrained to type 'new (...args: any[]) => {1}'?"),
Operator_0_cannot_be_applied_to_type_1: diag(2736, ts.DiagnosticCategory.Error, "Operator_0_cannot_be_applied_to_type_1_2736", "Operator '{0}' cannot be applied to type '{1}'."),
@@ -6917,6 +6917,7 @@ var ts;
scanJsxIdentifier: scanJsxIdentifier,
scanJsxAttributeValue: scanJsxAttributeValue,
reScanJsxToken: reScanJsxToken,
+ reScanLessThanToken: reScanLessThanToken,
scanJsxToken: scanJsxToken,
scanJSDocToken: scanJSDocToken,
scan: scan,
@@ -7913,6 +7914,13 @@ var ts;
pos = tokenPos = startPos;
return token = scanJsxToken();
}
+ function reScanLessThanToken() {
+ if (token === 46 /* LessThanLessThanToken */) {
+ pos = tokenPos + 1;
+ return token = 28 /* LessThanToken */;
+ }
+ return token;
+ }
function scanJsxToken() {
startPos = tokenPos = pos;
if (pos >= end) {
@@ -8849,7 +8857,9 @@ var ts;
case 14 /* NoSubstitutionTemplateLiteral */:
return ts.escapeLeadingUnderscores(name.text);
case 149 /* ComputedPropertyName */:
- return isStringOrNumericLiteralLike(name.expression) ? ts.escapeLeadingUnderscores(name.expression.text) : undefined; // TODO: GH#18217 Almost all uses of this assume the result to be defined!
+ if (isStringOrNumericLiteralLike(name.expression))
+ return ts.escapeLeadingUnderscores(name.expression.text);
+ return ts.Debug.fail("Text of property name cannot be read from non-literal-valued ComputedPropertyNames");
default:
return ts.Debug.assertNever(name);
}
@@ -17195,6 +17205,9 @@ var ts;
function reScanTemplateToken() {
return currentToken = scanner.reScanTemplateToken();
}
+ function reScanLessThanToken() {
+ return currentToken = scanner.reScanLessThanToken();
+ }
function scanJsxIdentifier() {
return currentToken = scanner.scanJsxIdentifier();
}
@@ -18206,7 +18219,7 @@ var ts;
function parseTypeReference() {
var node = createNode(164 /* TypeReference */);
node.typeName = parseEntityName(/*allowReservedWords*/ true, ts.Diagnostics.Type_expected);
- if (!scanner.hasPrecedingLineBreak() && token() === 28 /* LessThanToken */) {
+ if (!scanner.hasPrecedingLineBreak() && reScanLessThanToken() === 28 /* LessThanToken */) {
node.typeArguments = parseBracketedList(20 /* TypeArguments */, parseType, 28 /* LessThanToken */, 30 /* GreaterThanToken */);
}
return finishNode(node);
@@ -20228,7 +20241,8 @@ var ts;
function parseCallExpressionRest(expression) {
while (true) {
expression = parseMemberExpressionRest(expression);
- if (token() === 28 /* LessThanToken */) {
+ // handle 'foo<()'
+ if (token() === 28 /* LessThanToken */ || token() === 46 /* LessThanLessThanToken */) {
// See if this is the start of a generic invocation. If so, consume it and
// keep checking for postfix expressions. Otherwise, it's just a '<' that's
// part of an arithmetic expression. Break out so we consume it higher in the
@@ -20265,9 +20279,10 @@ var ts;
return result;
}
function parseTypeArgumentsInExpression() {
- if (!parseOptional(28 /* LessThanToken */)) {
+ if (reScanLessThanToken() !== 28 /* LessThanToken */) {
return undefined;
}
+ nextToken();
var typeArguments = parseDelimitedList(20 /* TypeArguments */, parseType);
if (!parseExpected(30 /* GreaterThanToken */)) {
// If it doesn't have the closing `>` then it's definitely not an type argument list.
@@ -27140,6 +27155,7 @@ var ts;
ContainerFlags[ContainerFlags["IsInterface"] = 64] = "IsInterface";
ContainerFlags[ContainerFlags["IsObjectLiteralOrClassExpressionMethod"] = 128] = "IsObjectLiteralOrClassExpressionMethod";
})(ContainerFlags || (ContainerFlags = {}));
+ var flowNodeCreated = ts.identity;
var binder = createBinder();
function bindSourceFile(file, options) {
ts.performance.mark("beforeBind");
@@ -27528,6 +27544,7 @@ var ts;
blockScopeContainer.locals = undefined;
}
if (containerFlags & 4 /* IsControlFlowContainer */) {
+ var saveFlowNodeCreated = flowNodeCreated;
var saveCurrentFlow = currentFlow;
var saveBreakTarget = currentBreakTarget;
var saveContinueTarget = currentContinueTarget;
@@ -27551,6 +27568,7 @@ var ts;
currentContinueTarget = undefined;
activeLabels = undefined;
hasExplicitReturn = false;
+ flowNodeCreated = ts.identity;
bindChildren(node);
// Reset all reachability check related flags on node (for incremental scenarios)
node.flags &= ~1408 /* ReachabilityAndEmitFlags */;
@@ -27577,6 +27595,7 @@ var ts;
currentReturnTarget = saveReturnTarget;
activeLabels = saveActiveLabels;
hasExplicitReturn = saveHasExplicitReturn;
+ flowNodeCreated = saveFlowNodeCreated;
}
else if (containerFlags & 64 /* IsInterface */) {
seenThisKeyword = false;
@@ -27840,22 +27859,22 @@ var ts;
return antecedent;
}
setFlowNodeReferenced(antecedent);
- return { flags: flags, expression: expression, antecedent: antecedent };
+ return flowNodeCreated({ flags: flags, expression: expression, antecedent: antecedent });
}
function createFlowSwitchClause(antecedent, switchStatement, clauseStart, clauseEnd) {
if (!isNarrowingExpression(switchStatement.expression)) {
return antecedent;
}
setFlowNodeReferenced(antecedent);
- return { flags: 128 /* SwitchClause */, switchStatement: switchStatement, clauseStart: clauseStart, clauseEnd: clauseEnd, antecedent: antecedent };
+ return flowNodeCreated({ flags: 128 /* SwitchClause */, switchStatement: switchStatement, clauseStart: clauseStart, clauseEnd: clauseEnd, antecedent: antecedent });
}
function createFlowAssignment(antecedent, node) {
setFlowNodeReferenced(antecedent);
- return { flags: 16 /* Assignment */, antecedent: antecedent, node: node };
+ return flowNodeCreated({ flags: 16 /* Assignment */, antecedent: antecedent, node: node });
}
function createFlowArrayMutation(antecedent, node) {
setFlowNodeReferenced(antecedent);
- var res = { flags: 256 /* ArrayMutation */, antecedent: antecedent, node: node };
+ var res = flowNodeCreated({ flags: 256 /* ArrayMutation */, antecedent: antecedent, node: node });
return res;
}
function finishFlowLabel(flow) {
@@ -28043,18 +28062,46 @@ var ts;
function bindTryStatement(node) {
var preFinallyLabel = createBranchLabel();
var preTryFlow = currentFlow;
- // TODO: Every statement in try block is potentially an exit point!
+ var tryPriors = [];
+ var oldFlowNodeCreated = flowNodeCreated;
+ // We hook the creation of all flow nodes within the `try` scope and store them so we can add _all_ of them
+ // as possible antecedents of the start of the `catch` or `finally` blocks.
+ // Don't bother intercepting the call if there's no finally or catch block that needs the information
+ if (node.catchClause || node.finallyBlock) {
+ flowNodeCreated = function (node) { return (tryPriors.push(node), node); };
+ }
bind(node.tryBlock);
+ flowNodeCreated = oldFlowNodeCreated;
addAntecedent(preFinallyLabel, currentFlow);
var flowAfterTry = currentFlow;
var flowAfterCatch = unreachableFlow;
if (node.catchClause) {
currentFlow = preTryFlow;
+ if (tryPriors.length) {
+ var preCatchFlow = createBranchLabel();
+ addAntecedent(preCatchFlow, currentFlow);
+ for (var _i = 0, tryPriors_1 = tryPriors; _i < tryPriors_1.length; _i++) {
+ var p = tryPriors_1[_i];
+ addAntecedent(preCatchFlow, p);
+ }
+ currentFlow = finishFlowLabel(preCatchFlow);
+ }
bind(node.catchClause);
addAntecedent(preFinallyLabel, currentFlow);
flowAfterCatch = currentFlow;
}
if (node.finallyBlock) {
+ // We add the nodes within the `try` block to the `finally`'s antecedents if there's no catch block
+ // (If there is a `catch` block, it will have all these antecedents instead, and the `finally` will
+ // have the end of the `try` block and the end of the `catch` block)
+ if (!node.catchClause) {
+ if (tryPriors.length) {
+ for (var _a = 0, tryPriors_2 = tryPriors; _a < tryPriors_2.length; _a++) {
+ var p = tryPriors_2[_a];
+ addAntecedent(preFinallyLabel, p);
+ }
+ }
+ }
// in finally flow is combined from pre-try/flow from try/flow from catch
// pre-flow is necessary to make sure that finally is reachable even if finally flows in both try and finally blocks are unreachable
// also for finally blocks we inject two extra edges into the flow graph.
@@ -28099,7 +28146,7 @@ var ts;
}
}
if (!(currentFlow.flags & 1 /* Unreachable */)) {
- var afterFinallyFlow = { flags: 4096 /* AfterFinally */, antecedent: currentFlow };
+ var afterFinallyFlow = flowNodeCreated({ flags: 4096 /* AfterFinally */, antecedent: currentFlow });
preFinallyFlow.lock = afterFinallyFlow;
currentFlow = afterFinallyFlow;
}
@@ -35625,16 +35672,17 @@ var ts;
var objectFlags = 128 /* ObjectLiteral */;
ts.forEach(pattern.elements, function (e) {
var name = e.propertyName || e.name;
- if (isComputedNonLiteralName(name)) {
- // do not include computed properties in the implied type
- objectFlags |= 512 /* ObjectLiteralPatternWithComputedProperties */;
- return;
- }
if (e.dotDotDotToken) {
stringIndexInfo = createIndexInfo(anyType, /*isReadonly*/ false);
return;
}
- var text = ts.getTextOfPropertyName(name);
+ var exprType = getLiteralTypeFromPropertyName(name);
+ if (!isTypeUsableAsPropertyName(exprType)) {
+ // do not include computed properties in the implied type
+ objectFlags |= 512 /* ObjectLiteralPatternWithComputedProperties */;
+ return;
+ }
+ var text = getPropertyNameFromType(exprType);
var flags = 4 /* Property */ | (e.initializer ? 16777216 /* Optional */ : 0);
var symbol = createSymbol(flags, text);
symbol.type = getTypeFromBindingElement(e, includePatternInType, reportErrors);
@@ -36676,9 +36724,9 @@ var ts;
return type;
}
/**
- * Indicates whether a type can be used as a late-bound name.
+ * Indicates whether a type can be used as a property name.
*/
- function isTypeUsableAsLateBoundName(type) {
+ function isTypeUsableAsPropertyName(type) {
return !!(type.flags & 8576 /* StringOrNumberLiteralOrUnique */);
}
/**
@@ -36692,7 +36740,7 @@ var ts;
function isLateBindableName(node) {
return ts.isComputedPropertyName(node)
&& ts.isEntityNameExpression(node.expression)
- && isTypeUsableAsLateBoundName(checkComputedPropertyName(node));
+ && isTypeUsableAsPropertyName(checkComputedPropertyName(node));
}
function isLateBoundName(name) {
return name.charCodeAt(0) === 95 /* _ */ &&
@@ -36719,11 +36767,11 @@ var ts;
return ts.isDynamicName(node) && !isLateBindableName(node);
}
/**
- * Gets the symbolic name for a late-bound member from its type.
+ * Gets the symbolic name for a member from its type.
*/
- function getLateBoundNameFromType(type) {
+ function getPropertyNameFromType(type) {
if (type.flags & 8192 /* UniqueESSymbol */) {
- return "__@" + type.symbol.escapedName + "@" + getSymbolId(type.symbol);
+ return type.escapedName;
}
if (type.flags & (128 /* StringLiteral */ | 256 /* NumberLiteral */)) {
return ts.escapeLeadingUnderscores("" + type.value);
@@ -36787,8 +36835,8 @@ var ts;
// fall back to the early-bound name of this member.
links.resolvedSymbol = decl.symbol;
var type = checkComputedPropertyName(decl.name);
- if (isTypeUsableAsLateBoundName(type)) {
- var memberName = getLateBoundNameFromType(type);
+ if (isTypeUsableAsPropertyName(type)) {
+ var memberName = getPropertyNameFromType(type);
var symbolFlags = decl.symbol.flags;
// Get or add a late-bound symbol for the member. This allows us to merge late-bound accessor declarations.
var lateSymbol = lateSymbols.get(memberName);
@@ -36802,9 +36850,9 @@ var ts;
// If we have an existing early-bound member, combine its declarations so that we can
// report an error at each declaration.
var declarations = earlySymbol ? ts.concatenate(earlySymbol.declarations, lateSymbol.declarations) : lateSymbol.declarations;
- var name_3 = ts.declarationNameToString(decl.name);
- ts.forEach(declarations, function (declaration) { return error(ts.getNameOfDeclaration(declaration) || declaration, ts.Diagnostics.Duplicate_declaration_0, name_3); });
- error(decl.name || decl, ts.Diagnostics.Duplicate_declaration_0, name_3);
+ var name_3 = !(type.flags & 8192 /* UniqueESSymbol */) && ts.unescapeLeadingUnderscores(memberName) || ts.declarationNameToString(decl.name);
+ ts.forEach(declarations, function (declaration) { return error(ts.getNameOfDeclaration(declaration) || declaration, ts.Diagnostics.Property_0_was_also_declared_here, name_3); });
+ error(decl.name || decl, ts.Diagnostics.Duplicate_property_0, name_3);
lateSymbol = createSymbol(0 /* None */, memberName, 2048 /* Late */);
}
lateSymbol.nameType = type;
@@ -37396,8 +37444,8 @@ var ts;
var propType = instantiateType(templateType, templateMapper);
// If the current iteration type constituent is a string literal type, create a property.
// Otherwise, for type string create a string index signature.
- if (t.flags & 8576 /* StringOrNumberLiteralOrUnique */) {
- var propName = getLateBoundNameFromType(t);
+ if (isTypeUsableAsPropertyName(t)) {
+ var propName = getPropertyNameFromType(t);
var modifiersProp = getPropertyOfType(modifiersType, propName);
var isOptional = !!(templateModifiers & 4 /* IncludeOptional */ ||
!(templateModifiers & 8 /* ExcludeOptional */) && modifiersProp && modifiersProp.flags & 16777216 /* Optional */);
@@ -37567,7 +37615,8 @@ var ts;
function isTypeInvalidDueToUnionDiscriminant(contextualType, obj) {
var list = obj.properties;
return list.some(function (property) {
- var name = property.name && ts.getTextOfPropertyName(property.name);
+ var nameType = property.name && getLiteralTypeFromPropertyName(property.name);
+ var name = nameType && isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined;
var expected = name === undefined ? undefined : getTypeOfPropertyOfType(contextualType, name);
return !!expected && isLiteralType(expected) && !isTypeIdenticalTo(getTypeOfNode(property), expected);
});
@@ -37937,6 +37986,10 @@ var ts;
result.containingType = containingType;
if (!hasNonUniformValueDeclaration && firstValueDeclaration) {
result.valueDeclaration = firstValueDeclaration;
+ // Inherit information about parent type.
+ if (firstValueDeclaration.symbol.parent) {
+ result.parent = firstValueDeclaration.symbol.parent;
+ }
}
result.declarations = declarations;
result.nameType = nameType;
@@ -38795,21 +38848,16 @@ var ts;
* the type of this reference is just the type of the value we resolved to.
*/
function getJSDocTypeReference(node, symbol, typeArguments) {
- if (!pushTypeResolution(symbol, 6 /* JSDocTypeReference */)) {
- return errorType;
- }
- var assignedType = getAssignedClassType(symbol);
- var valueType = getTypeOfSymbol(symbol);
- var referenceType = valueType.symbol && valueType.symbol !== symbol && !isInferredClassType(valueType) && getTypeReferenceTypeWorker(node, valueType.symbol, typeArguments);
- if (!popTypeResolution()) {
- getSymbolLinks(symbol).resolvedJSDocType = errorType;
- error(node, ts.Diagnostics.JSDoc_type_0_circularly_references_itself, symbolToString(symbol));
- return errorType;
- }
- if (referenceType || assignedType) {
- // TODO: GH#18217 (should the `|| assignedType` be at a lower precedence?)
- var type = (referenceType && assignedType ? getIntersectionType([assignedType, referenceType]) : referenceType || assignedType);
- return getSymbolLinks(symbol).resolvedJSDocType = type;
+ // In the case of an assignment of a function expression (binary expressions, variable declarations, etc.), we will get the
+ // correct instance type for the symbol on the LHS by finding the type for RHS. For example if we want to get the type of the symbol `foo`:
+ // var foo = function() {}
+ // We will find the static type of the assigned anonymous function.
+ var staticType = getTypeOfSymbol(symbol);
+ var instanceType = staticType.symbol &&
+ staticType.symbol !== symbol && // Make sure this is an assignment like expression by checking that symbol -> type -> symbol doesn't roundtrips.
+ getTypeReferenceTypeWorker(node, staticType.symbol, typeArguments); // Get the instance type of the RHS symbol.
+ if (instanceType) {
+ return getSymbolLinks(symbol).resolvedJSDocType = instanceType;
}
}
function getTypeReferenceTypeWorker(node, symbol, typeArguments) {
@@ -38827,8 +38875,11 @@ var ts;
}
if (symbol.flags & 16 /* Function */ &&
isJSDocTypeReference(node) &&
- (symbol.members || ts.getJSDocClassTag(symbol.valueDeclaration))) {
- return getInferredClassType(symbol);
+ isJSConstructor(symbol.valueDeclaration)) {
+ var resolved = resolveStructuredTypeMembers(getTypeOfSymbol(symbol));
+ if (resolved.callSignatures.length === 1) {
+ return getReturnTypeOfSignature(resolved.callSignatures[0]);
+ }
}
}
function getSubstitutionType(typeVariable, substitute) {
@@ -39725,8 +39776,8 @@ var ts;
}
function getPropertyTypeForIndexType(objectType, indexType, accessNode, cacheSymbol, missingType) {
var accessExpression = accessNode && accessNode.kind === 190 /* ElementAccessExpression */ ? accessNode : undefined;
- var propName = isTypeUsableAsLateBoundName(indexType) ?
- getLateBoundNameFromType(indexType) :
+ var propName = isTypeUsableAsPropertyName(indexType) ?
+ getPropertyNameFromType(indexType) :
accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ?
ts.getPropertyNameForKnownSymbolName(ts.idText(accessExpression.argumentExpression.name)) :
accessNode && ts.isPropertyName(accessNode) ?
@@ -40370,6 +40421,7 @@ var ts;
function createUniqueESSymbolType(symbol) {
var type = createType(8192 /* UniqueESSymbol */);
type.symbol = symbol;
+ type.escapedName = "__@" + type.symbol.escapedName + "@" + getSymbolId(type.symbol);
return type;
}
function getESSymbolLikeTypeForNode(node) {
@@ -40567,7 +40619,9 @@ var ts;
return type.flags & 262144 /* TypeParameter */ ? wildcardType : type;
}
function getRestrictiveTypeParameter(tp) {
- return !tp.constraint ? tp : tp.restrictiveInstantiation || (tp.restrictiveInstantiation = createTypeParameter(tp.symbol));
+ return tp.constraint === unknownType ? tp : tp.restrictiveInstantiation || (tp.restrictiveInstantiation = createTypeParameter(tp.symbol),
+ tp.restrictiveInstantiation.constraint = unknownType,
+ tp.restrictiveInstantiation);
}
function restrictiveMapper(type) {
return type.flags & 262144 /* TypeParameter */ ? getRestrictiveTypeParameter(type) : type;
@@ -41182,7 +41236,7 @@ var ts;
}
if (resultObj.error) {
var reportedDiag = resultObj.error;
- var propertyName = isTypeUsableAsLateBoundName(nameType) ? getLateBoundNameFromType(nameType) : undefined;
+ var propertyName = isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined;
var targetProp = propertyName !== undefined ? getPropertyOfType(target, propertyName) : undefined;
var issuedElaboration = false;
if (!targetProp) {
@@ -42538,7 +42592,7 @@ var ts;
}
else {
// An empty object type is related to any mapped type that includes a '?' modifier.
- if (isPartialMappedType(target) && isEmptyObjectType(source)) {
+ if (relation !== subtypeRelation && isPartialMappedType(target) && isEmptyObjectType(source)) {
return -1 /* True */;
}
if (isGenericMappedType(target)) {
@@ -44342,7 +44396,11 @@ var ts;
priority |= 4 /* MappedTypeConstraint */;
inferFromTypes(getIndexType(source), constraintType);
priority = savePriority;
- inferFromTypes(getUnionType(ts.map(getPropertiesOfType(source), getTypeOfSymbol)), getTemplateTypeFromMappedType(target));
+ var valueTypes = ts.compact([
+ getIndexTypeOfType(source, 0 /* String */),
+ getIndexTypeOfType(source, 1 /* Number */)
+ ].concat(ts.map(getPropertiesOfType(source), getTypeOfSymbol)));
+ inferFromTypes(getUnionType(valueTypes), getTemplateTypeFromMappedType(target));
return true;
}
return false;
@@ -44899,7 +44957,10 @@ var ts;
return type;
}
function getTypeOfDestructuredProperty(type, name) {
- var text = ts.getTextOfPropertyName(name);
+ var nameType = getLiteralTypeFromPropertyName(name);
+ if (!isTypeUsableAsPropertyName(nameType))
+ return errorType;
+ var text = getPropertyNameFromType(nameType);
return getConstraintForLocation(getTypeOfPropertyOfType(type, text), name) ||
isNumericLiteralName(text) && getIndexTypeOfType(type, 1 /* Number */) ||
getIndexTypeOfType(type, 0 /* String */) ||
@@ -45457,9 +45518,6 @@ var ts;
}
function getTypeAtSwitchClause(flow) {
var expr = flow.switchStatement.expression;
- if (containsMatchingReferenceDiscriminant(reference, expr)) {
- return declaredType;
- }
var flowType = getTypeAtFlowNode(flow.antecedent);
var type = getTypeFromFlowType(flowType);
if (isMatchingReference(reference, expr)) {
@@ -45471,6 +45529,9 @@ var ts;
else if (expr.kind === 199 /* TypeOfExpression */ && isMatchingReference(reference, expr.expression)) {
type = narrowBySwitchOnTypeOf(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd);
}
+ else if (containsMatchingReferenceDiscriminant(reference, expr)) {
+ type = declaredType;
+ }
return createFlowType(type, isIncomplete(flowType));
}
function getTypeAtFlowBranchLabel(flow) {
@@ -46463,7 +46524,7 @@ var ts;
else if (isInJS &&
(container.kind === 196 /* FunctionExpression */ || container.kind === 239 /* FunctionDeclaration */) &&
ts.getJSDocClassTag(container)) {
- var classType = getJSClassType(container.symbol);
+ var classType = getJSClassType(getMergedSymbol(container.symbol));
if (classType) {
return getFlowTypeOfReference(node, classType);
}
@@ -46858,9 +46919,10 @@ var ts;
var parentDeclaration = declaration.parent.parent;
var name = declaration.propertyName || declaration.name;
var parentType = getContextualTypeForVariableLikeDeclaration(parentDeclaration);
- if (parentType && !ts.isBindingPattern(name)) {
- var text = ts.getTextOfPropertyName(name);
- if (text !== undefined) {
+ if (parentType && !ts.isBindingPattern(name) && !isComputedNonLiteralName(name)) {
+ var nameType = getLiteralTypeFromPropertyName(name);
+ if (isTypeUsableAsPropertyName(nameType)) {
+ var text = getPropertyNameFromType(nameType);
return getTypeOfPropertyOfType(parentType, text);
}
}
@@ -47734,10 +47796,9 @@ var ts;
}
}
typeFlags |= type.flags;
- var nameType = computedNameType && computedNameType.flags & 8576 /* StringOrNumberLiteralOrUnique */ ?
- computedNameType : undefined;
+ var nameType = computedNameType && isTypeUsableAsPropertyName(computedNameType) ? computedNameType : undefined;
var prop = nameType ?
- createSymbol(4 /* Property */ | member.flags, getLateBoundNameFromType(nameType), 2048 /* Late */) :
+ createSymbol(4 /* Property */ | member.flags, getPropertyNameFromType(nameType), 2048 /* Late */) :
createSymbol(4 /* Property */ | member.flags, member.escapedName);
if (nameType) {
prop.nameType = nameType;
@@ -47995,6 +48056,10 @@ var ts;
childrenPropSymbol.type = childrenTypes.length === 1 ?
childrenTypes[0] :
(getArrayLiteralTupleTypeIfApplicable(childrenTypes, childrenContextualType, /*hasRestElement*/ false) || createArrayType(getUnionType(childrenTypes)));
+ // Fake up a property declaration for the children
+ childrenPropSymbol.valueDeclaration = ts.createPropertySignature(/*modifiers*/ undefined, ts.unescapeLeadingUnderscores(jsxChildrenPropertyName), /*questionToken*/ undefined, /*type*/ undefined, /*initializer*/ undefined);
+ childrenPropSymbol.valueDeclaration.parent = attributes;
+ childrenPropSymbol.valueDeclaration.symbol = childrenPropSymbol;
var childPropMap = ts.createSymbolTable();
childPropMap.set(jsxChildrenPropertyName, childrenPropSymbol);
spread = getSpreadType(spread, createAnonymousType(attributes.symbol, childPropMap, ts.emptyArray, ts.emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined), attributes.symbol, typeFlags, objectFlags);
@@ -49674,6 +49739,12 @@ var ts;
if (inferenceContext) {
var typeArgumentTypes = inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext);
checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration));
+ // If the original signature has a generic rest type, instantiation may produce a
+ // signature with different arity and we need to perform another arity check.
+ if (getNonArrayRestType(candidate) && !hasCorrectArity(node, args, checkCandidate, signatureHelpTrailingComma)) {
+ candidateForArgumentArityError = checkCandidate;
+ continue;
+ }
}
if (!checkApplicableSignature(node, args, checkCandidate, relation, excludeArgument, /*reportErrors*/ false)) {
// Give preference to error candidates that have no rest parameters (as they are more specific)
@@ -50225,7 +50296,7 @@ var ts;
return true;
// If the symbol of the node has members, treat it like a constructor.
var symbol = getSymbolOfNode(func);
- return !!symbol && symbol.members !== undefined;
+ return !!symbol && (symbol.members !== undefined || symbol.exports !== undefined && symbol.exports.get("prototype") !== undefined);
}
return false;
}
@@ -50242,10 +50313,6 @@ var ts;
inferred = getInferredClassType(symbol);
}
var assigned = getAssignedClassType(symbol);
- var valueType = getTypeOfSymbol(symbol);
- if (valueType.symbol && !isInferredClassType(valueType) && isJSConstructor(valueType.symbol.valueDeclaration)) {
- inferred = getInferredClassType(valueType.symbol);
- }
return assigned && inferred ?
getIntersectionType([inferred, assigned]) :
assigned || inferred;
@@ -50280,11 +50347,6 @@ var ts;
}
return links.inferredClassType;
}
- function isInferredClassType(type) {
- return type.symbol
- && ts.getObjectFlags(type) & 16 /* Anonymous */
- && getSymbolLinks(type.symbol).inferredClassType === type;
- }
/**
* Syntactically and semantically checks a call or new expression.
* @param node The call/new expression to be checked.
@@ -50303,20 +50365,9 @@ var ts;
declaration.kind !== 157 /* Constructor */ &&
declaration.kind !== 161 /* ConstructSignature */ &&
declaration.kind !== 166 /* ConstructorType */ &&
- !ts.isJSDocConstructSignature(declaration)) {
- // When resolved signature is a call signature (and not a construct signature) the result type is any, unless
- // the declaring function had members created through 'x.prototype.y = expr' or 'this.y = expr' psuedodeclarations
- // in a JS file
- // Note:JS inferred classes might come from a variable declaration instead of a function declaration.
- // In this case, using getResolvedSymbol directly is required to avoid losing the members from the declaration.
- var funcSymbol = checkExpression(node.expression).symbol;
- if (!funcSymbol && node.expression.kind === 72 /* Identifier */) {
- funcSymbol = getResolvedSymbol(node.expression);
- }
- var type = funcSymbol && getJSClassType(funcSymbol);
- if (type) {
- return signature.target ? instantiateType(type, signature.mapper) : type;
- }
+ !ts.isJSDocConstructSignature(declaration) &&
+ !isJSConstructor(declaration)) {
+ // When resolved signature is a call signature (and not a construct signature) the result type is any
if (noImplicitAny) {
error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type);
}
@@ -51371,7 +51422,7 @@ var ts;
if (!(isTypeComparableTo(leftType, stringType) || isTypeAssignableToKind(leftType, 296 /* NumberLike */ | 12288 /* ESSymbolLike */))) {
error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol);
}
- if (!isTypeAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */)) {
+ if (!allTypesAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */)) {
error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
}
return booleanType;
@@ -51392,15 +51443,15 @@ var ts;
if (rightIsThis === void 0) { rightIsThis = false; }
if (property.kind === 275 /* PropertyAssignment */ || property.kind === 276 /* ShorthandPropertyAssignment */) {
var name = property.name;
- var text = ts.getTextOfPropertyName(name);
- if (text) {
+ var exprType = getLiteralTypeFromPropertyName(name);
+ if (isTypeUsableAsPropertyName(exprType)) {
+ var text = getPropertyNameFromType(exprType);
var prop = getPropertyOfType(objectLiteralType, text);
if (prop) {
markPropertyAsReferenced(prop, property, rightIsThis);
checkPropertyAccessibility(property, /*isSuper*/ false, objectLiteralType, prop);
}
}
- var exprType = getLiteralTypeFromPropertyName(name);
var elementType = getIndexedAccessType(objectLiteralType, exprType, name);
var type = getFlowTypeOfDestructuring(property, elementType);
return checkDestructuringAssignment(property.kind === 276 /* ShorthandPropertyAssignment */ ? property : property.initializer, type);
@@ -54390,10 +54441,11 @@ var ts;
var parent = node.parent.parent;
var parentType = getTypeForBindingElementParent(parent);
var name = node.propertyName || node.name;
- if (!ts.isBindingPattern(name)) {
- var nameText = ts.getTextOfPropertyName(name);
- if (nameText) {
- var property = getPropertyOfType(parentType, nameText); // TODO: GH#18217
+ if (!ts.isBindingPattern(name) && parentType) {
+ var exprType = getLiteralTypeFromPropertyName(name);
+ if (isTypeUsableAsPropertyName(exprType)) {
+ var nameText = getPropertyNameFromType(exprType);
+ var property = getPropertyOfType(parentType, nameText);
if (property) {
markPropertyAsReferenced(property, /*nodeForCheckWriteOnly*/ undefined, /*isThisAccess*/ false); // A destructuring is never a write-only reference.
checkPropertyAccessibility(parent, !!parent.initializer && parent.initializer.kind === 98 /* SuperKeyword */, parentType, property);
@@ -54750,7 +54802,7 @@ var ts;
? downlevelIteration
? ts.Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator
: isIterable
- ? ts.Diagnostics.Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators
+ ? ts.Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators
: ts.Diagnostics.Type_0_is_not_an_array_type
: downlevelIteration
? ts.Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator
@@ -59392,6 +59444,7 @@ var ts;
if (nodeArguments.length !== 1) {
return grammarErrorOnNode(node, ts.Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument);
}
+ checkGrammarForDisallowedTrailingComma(nodeArguments);
// see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import.
// parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import.
if (ts.isSpreadElement(nodeArguments[0])) {
@@ -61824,22 +61877,62 @@ var ts;
return node;
}
ts.createBundle = createBundle;
- function createUnparsedSourceFile(text, mapPath, map) {
+ function createUnparsedSourceFile(textOrInputFiles, mapPathOrType, map) {
var node = ts.createNode(281 /* UnparsedSource */);
- node.text = text;
- node.sourceMapPath = mapPath;
- node.sourceMapText = map;
+ if (!ts.isString(textOrInputFiles)) {
+ ts.Debug.assert(mapPathOrType === "js" || mapPathOrType === "dts");
+ node.fileName = mapPathOrType === "js" ? textOrInputFiles.javascriptPath : textOrInputFiles.declarationPath;
+ node.sourceMapPath = mapPathOrType === "js" ? textOrInputFiles.javascriptMapPath : textOrInputFiles.declarationMapPath;
+ Object.defineProperties(node, {
+ text: { get: function () { return mapPathOrType === "js" ? textOrInputFiles.javascriptText : textOrInputFiles.declarationText; } },
+ sourceMapText: { get: function () { return mapPathOrType === "js" ? textOrInputFiles.javascriptMapText : textOrInputFiles.declarationMapText; } },
+ });
+ }
+ else {
+ node.text = textOrInputFiles;
+ node.sourceMapPath = mapPathOrType;
+ node.sourceMapText = map;
+ }
return node;
}
ts.createUnparsedSourceFile = createUnparsedSourceFile;
- function createInputFiles(javascript, declaration, javascriptMapPath, javascriptMapText, declarationMapPath, declarationMapText) {
+ function createInputFiles(javascriptTextOrReadFileText, declarationTextOrJavascriptPath, javascriptMapPath, javascriptMapTextOrDeclarationPath, declarationMapPath, declarationMapText) {
var node = ts.createNode(282 /* InputFiles */);
- node.javascriptText = javascript;
- node.javascriptMapPath = javascriptMapPath;
- node.javascriptMapText = javascriptMapText;
- node.declarationText = declaration;
- node.declarationMapPath = declarationMapPath;
- node.declarationMapText = declarationMapText;
+ if (!ts.isString(javascriptTextOrReadFileText)) {
+ var cache_1 = ts.createMap();
+ var textGetter_1 = function (path) {
+ if (path === undefined)
+ return undefined;
+ var value = cache_1.get(path);
+ if (value === undefined) {
+ value = javascriptTextOrReadFileText(path);
+ cache_1.set(path, value !== undefined ? value : false);
+ }
+ return value !== false ? value : undefined;
+ };
+ var definedTextGetter_1 = function (path) {
+ var result = textGetter_1(path);
+ return result !== undefined ? result : "/* Input file " + path + " was missing */\r\n";
+ };
+ node.javascriptPath = declarationTextOrJavascriptPath;
+ node.javascriptMapPath = javascriptMapPath;
+ node.declarationPath = ts.Debug.assertDefined(javascriptMapTextOrDeclarationPath);
+ node.declarationMapPath = declarationMapPath;
+ Object.defineProperties(node, {
+ javascriptText: { get: function () { return definedTextGetter_1(declarationTextOrJavascriptPath); } },
+ javascriptMapText: { get: function () { return textGetter_1(javascriptMapPath); } },
+ declarationText: { get: function () { return definedTextGetter_1(ts.Debug.assertDefined(javascriptMapTextOrDeclarationPath)); } },
+ declarationMapText: { get: function () { return textGetter_1(declarationMapPath); } } // TODO:: if there is inline sourceMap in dtsFile, use that
+ });
+ }
+ else {
+ node.javascriptText = javascriptTextOrReadFileText;
+ node.javascriptMapPath = javascriptMapPath;
+ node.javascriptMapText = javascriptMapTextOrDeclarationPath;
+ node.declarationText = declarationTextOrJavascriptPath;
+ node.declarationMapPath = declarationMapPath;
+ node.declarationMapText = declarationMapText;
+ }
return node;
}
ts.createInputFiles = createInputFiles;
@@ -66190,7 +66283,7 @@ var ts;
function transformBundle(node) {
return ts.createBundle(node.sourceFiles.map(transformSourceFile), ts.mapDefined(node.prepends, function (prepend) {
if (prepend.kind === 282 /* InputFiles */) {
- return ts.createUnparsedSourceFile(prepend.javascriptText, prepend.javascriptMapPath, prepend.javascriptMapText);
+ return ts.createUnparsedSourceFile(prepend, "js");
}
return prepend;
}));
@@ -80423,7 +80516,7 @@ var ts;
return ts.updateSourceFileNode(sourceFile, transformAndReplaceLatePaintedStatements(updated), /*isDeclarationFile*/ true, /*referencedFiles*/ [], /*typeReferences*/ [], /*hasNoDefaultLib*/ false, /*libReferences*/ []);
}), ts.mapDefined(node.prepends, function (prepend) {
if (prepend.kind === 282 /* InputFiles */) {
- return ts.createUnparsedSourceFile(prepend.declarationText, prepend.declarationMapPath, prepend.declarationMapText);
+ return ts.createUnparsedSourceFile(prepend, "dts");
}
}));
bundle.syntheticFileReferences = [];
@@ -81784,16 +81877,21 @@ var ts;
}
ts.forEachEmittedFile = forEachEmittedFile;
/*@internal*/
+ function getOutputPathsForBundle(options, forceDtsPaths) {
+ var outPath = options.outFile || options.out;
+ var jsFilePath = options.emitDeclarationOnly ? undefined : outPath;
+ var sourceMapFilePath = jsFilePath && getSourceMapFilePath(jsFilePath, options);
+ var declarationFilePath = (forceDtsPaths || ts.getEmitDeclarations(options)) ? ts.removeFileExtension(outPath) + ".d.ts" /* Dts */ : undefined;
+ var declarationMapPath = declarationFilePath && ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
+ var bundleInfoPath = options.references && jsFilePath ? (ts.removeFileExtension(jsFilePath) + infoExtension) : undefined;
+ return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: bundleInfoPath };
+ }
+ ts.getOutputPathsForBundle = getOutputPathsForBundle;
+ /*@internal*/
function getOutputPathsFor(sourceFile, host, forceDtsPaths) {
var options = host.getCompilerOptions();
if (sourceFile.kind === 280 /* Bundle */) {
- var outPath = options.outFile || options.out;
- var jsFilePath = options.emitDeclarationOnly ? undefined : outPath;
- var sourceMapFilePath = jsFilePath && getSourceMapFilePath(jsFilePath, options);
- var declarationFilePath = (forceDtsPaths || ts.getEmitDeclarations(options)) ? ts.removeFileExtension(outPath) + ".d.ts" /* Dts */ : undefined;
- var declarationMapPath = declarationFilePath && ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
- var bundleInfoPath = options.references && jsFilePath ? (ts.removeFileExtension(jsFilePath) + infoExtension) : undefined;
- return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: bundleInfoPath };
+ return getOutputPathsForBundle(options, forceDtsPaths);
}
else {
var ownOutputFilePath = ts.getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options));
@@ -85588,10 +85686,10 @@ var ts;
}
}
/**
- * Skips trivia such as comments and white-space that can optionally overriden by the source map source
+ * Skips trivia such as comments and white-space that can be optionally overridden by the source-map source
*/
function skipSourceTrivia(source, pos) {
- return source.skipTrivia ? source.skipTrivia(pos) : ts.skipTrivia(sourceMapSource.text, pos);
+ return source.skipTrivia ? source.skipTrivia(pos) : ts.skipTrivia(source.text, pos);
}
/**
* Emits a mapping.
@@ -87262,14 +87360,12 @@ var ts;
// Upstream project didn't have outFile set -- skip (error will have been issued earlier)
if (!out)
continue;
- var dtsFilename = ts.changeExtension(out, ".d.ts");
- var js = host.readFile(out) || "/* Input file " + out + " was missing */\r\n";
- var jsMapPath = out + ".map"; // TODO: try to read sourceMappingUrl comment from the file
- var jsMap = host.readFile(jsMapPath);
- var dts = host.readFile(dtsFilename) || "/* Input file " + dtsFilename + " was missing */\r\n";
- var dtsMapPath = dtsFilename + ".map";
- var dtsMap = host.readFile(dtsMapPath);
- var node = ts.createInputFiles(js, dts, jsMap && jsMapPath, jsMap, dtsMap && dtsMapPath, dtsMap);
+ var _a = ts.getOutputPathsForBundle(resolvedRefOpts.options, /*forceDtsPaths*/ true), jsFilePath = _a.jsFilePath, sourceMapFilePath = _a.sourceMapFilePath, declarationFilePath = _a.declarationFilePath, declarationMapPath = _a.declarationMapPath;
+ var node = ts.createInputFiles(function (fileName) {
+ var path = toPath(fileName);
+ var sourceFile = getSourceFileByPath(path);
+ return sourceFile ? sourceFile.text : filesByName.has(path) ? undefined : host.readFile(path);
+ }, jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath);
nodes.push(node);
}
}
@@ -99973,6 +100069,11 @@ var ts;
}
return ts.createTextSpanFromBounds(start, end);
}
+ function getTextSpanOfEntry(entry) {
+ return entry.kind === 0 /* Span */ ? entry.textSpan :
+ getTextSpan(entry.node, entry.node.getSourceFile());
+ }
+ FindAllReferences.getTextSpanOfEntry = getTextSpanOfEntry;
/** A node is considered a writeAccess iff it is a name of a declaration or a target of an assignment */
function isWriteAccessForReference(node) {
var decl = ts.getDeclarationFromName(node);
@@ -100066,24 +100167,100 @@ var ts;
if (symbol.escapedName === "export=" /* ExportEquals */) {
return getReferencedSymbolsForModule(program, symbol.parent, /*excludeImportTypeOfExportEquals*/ false, sourceFiles, sourceFilesSet);
}
- var moduleReferences = ts.emptyArray;
- var moduleSourceFile = isModuleSymbol(symbol);
- var referencedNode = node;
- if (moduleSourceFile) {
- var exportEquals = symbol.exports.get("export=" /* ExportEquals */);
- // If !!exportEquals, we're about to add references to `import("mod")` anyway, so don't double-count them.
- moduleReferences = getReferencedSymbolsForModule(program, symbol, !!exportEquals, sourceFiles, sourceFilesSet);
- if (!exportEquals || !sourceFilesSet.has(moduleSourceFile.fileName))
- return moduleReferences;
- // Continue to get references to 'export ='.
- symbol = ts.skipAlias(exportEquals, checker);
- referencedNode = undefined;
- }
- return ts.concatenate(moduleReferences, getReferencedSymbolsForSymbol(symbol, referencedNode, sourceFiles, sourceFilesSet, checker, cancellationToken, options));
+ var moduleReferences = getReferencedSymbolsForModuleIfDeclaredBySourceFile(symbol, program, sourceFiles, cancellationToken, options, sourceFilesSet);
+ if (moduleReferences && !(symbol.flags & 33554432 /* Transient */)) {
+ return moduleReferences;
+ }
+ var aliasedSymbol = getMergedAliasedSymbolOfNamespaceExportDeclaration(node, symbol, checker);
+ var moduleReferencesOfExportTarget = aliasedSymbol &&
+ getReferencedSymbolsForModuleIfDeclaredBySourceFile(aliasedSymbol, program, sourceFiles, cancellationToken, options, sourceFilesSet);
+ var references = getReferencedSymbolsForSymbol(symbol, node, sourceFiles, sourceFilesSet, checker, cancellationToken, options);
+ return mergeReferences(program, moduleReferences, references, moduleReferencesOfExportTarget);
}
Core.getReferencedSymbolsForNode = getReferencedSymbolsForNode;
- function isModuleSymbol(symbol) {
- return symbol.flags & 1536 /* Module */ ? ts.find(symbol.declarations, ts.isSourceFile) : undefined;
+ function getMergedAliasedSymbolOfNamespaceExportDeclaration(node, symbol, checker) {
+ if (node.parent && ts.isNamespaceExportDeclaration(node.parent)) {
+ var aliasedSymbol = checker.getAliasedSymbol(symbol);
+ var targetSymbol = checker.getMergedSymbol(aliasedSymbol);
+ if (aliasedSymbol !== targetSymbol) {
+ return targetSymbol;
+ }
+ }
+ return undefined;
+ }
+ function getReferencedSymbolsForModuleIfDeclaredBySourceFile(symbol, program, sourceFiles, cancellationToken, options, sourceFilesSet) {
+ var moduleSourceFile = symbol.flags & 1536 /* Module */ ? ts.find(symbol.declarations, ts.isSourceFile) : undefined;
+ if (!moduleSourceFile)
+ return undefined;
+ var exportEquals = symbol.exports.get("export=" /* ExportEquals */);
+ // If !!exportEquals, we're about to add references to `import("mod")` anyway, so don't double-count them.
+ var moduleReferences = getReferencedSymbolsForModule(program, symbol, !!exportEquals, sourceFiles, sourceFilesSet);
+ if (!exportEquals || !sourceFilesSet.has(moduleSourceFile.fileName))
+ return moduleReferences;
+ // Continue to get references to 'export ='.
+ var checker = program.getTypeChecker();
+ symbol = ts.skipAlias(exportEquals, checker);
+ return mergeReferences(program, moduleReferences, getReferencedSymbolsForSymbol(symbol, /*node*/ undefined, sourceFiles, sourceFilesSet, checker, cancellationToken, options));
+ }
+ /**
+ * Merges the references by sorting them (by file index in sourceFiles and their location in it) that point to same definition symbol
+ */
+ function mergeReferences(program) {
+ var referencesToMerge = [];
+ for (var _i = 1; _i < arguments.length; _i++) {
+ referencesToMerge[_i - 1] = arguments[_i];
+ }
+ var result;
+ for (var _a = 0, referencesToMerge_1 = referencesToMerge; _a < referencesToMerge_1.length; _a++) {
+ var references = referencesToMerge_1[_a];
+ if (!references || !references.length)
+ continue;
+ if (!result) {
+ result = references;
+ continue;
+ }
+ var _loop_13 = function (entry) {
+ if (!entry.definition || entry.definition.type !== 0 /* Symbol */) {
+ result.push(entry);
+ return "continue";
+ }
+ var symbol = entry.definition.symbol;
+ var refIndex = ts.findIndex(result, function (ref) { return !!ref.definition &&
+ ref.definition.type === 0 /* Symbol */ &&
+ ref.definition.symbol === symbol; });
+ if (refIndex === -1) {
+ result.push(entry);
+ return "continue";
+ }
+ var reference = result[refIndex];
+ result[refIndex] = {
+ definition: reference.definition,
+ references: reference.references.concat(entry.references).sort(function (entry1, entry2) {
+ var entry1File = getSourceFileIndexOfEntry(program, entry1);
+ var entry2File = getSourceFileIndexOfEntry(program, entry2);
+ if (entry1File !== entry2File) {
+ return ts.compareValues(entry1File, entry2File);
+ }
+ var entry1Span = FindAllReferences.getTextSpanOfEntry(entry1);
+ var entry2Span = FindAllReferences.getTextSpanOfEntry(entry2);
+ return entry1Span.start !== entry2Span.start ?
+ ts.compareValues(entry1Span.start, entry2Span.start) :
+ ts.compareValues(entry1Span.length, entry2Span.length);
+ })
+ };
+ };
+ for (var _b = 0, references_1 = references; _b < references_1.length; _b++) {
+ var entry = references_1[_b];
+ _loop_13(entry);
+ }
+ }
+ return result;
+ }
+ function getSourceFileIndexOfEntry(program, entry) {
+ var sourceFile = entry.kind === 0 /* Span */ ?
+ program.getSourceFile(entry.fileName) :
+ entry.node.getSourceFile();
+ return program.getSourceFiles().indexOf(sourceFile);
}
function getReferencedSymbolsForModule(program, symbol, excludeImportTypeOfExportEquals, sourceFiles, sourceFilesSet) {
ts.Debug.assert(!!symbol.valueDeclaration);
@@ -100120,7 +100297,7 @@ var ts;
break;
default:
// This may be merged with something.
- ts.Debug.fail("Expected a module symbol to be declared by a SourceFile or ModuleDeclaration.");
+ ts.Debug.assert(!!(symbol.flags & 33554432 /* Transient */), "Expected a module symbol to be declared by a SourceFile or ModuleDeclaration.");
}
}
var exported = symbol.exports.get("export=" /* ExportEquals */);
@@ -100223,6 +100400,9 @@ var ts;
// If the symbol is declared as part of a declaration like `{ type: "a" } | { type: "b" }`, use the property on the union type to get more references.
return ts.firstDefined(symbol.declarations, function (decl) {
if (!decl.parent) {
+ // Ignore UMD module and global merge
+ if (symbol.flags & 33554432 /* Transient */)
+ return undefined;
// Assertions for GH#21814. We should be handling SourceFile symbols in `getReferencedSymbolsForModule` instead of getting here.
ts.Debug.fail("Unexpected symbol at " + ts.Debug.showSyntaxKind(node) + ": " + ts.Debug.showSymbol(symbol));
}
@@ -100237,6 +100417,12 @@ var ts;
SpecialSearchKind[SpecialSearchKind["Constructor"] = 1] = "Constructor";
SpecialSearchKind[SpecialSearchKind["Class"] = 2] = "Class";
})(SpecialSearchKind || (SpecialSearchKind = {}));
+ function getNonModuleSymbolOfMergedModuleSymbol(symbol) {
+ if (!(symbol.flags & (1536 /* Module */ | 33554432 /* Transient */)))
+ return undefined;
+ var decl = symbol.declarations && ts.find(symbol.declarations, function (d) { return !ts.isSourceFile(d) && !ts.isModuleDeclaration(d); });
+ return decl && decl.symbol;
+ }
/**
* Holds all state needed for the finding references.
* Unlike `Search`, there is only one `State`.
@@ -100295,7 +100481,7 @@ var ts;
// Note: getLocalSymbolForExportDefault handles `export default class C {}`, but not `export default C` or `export { C as default }`.
// The other two forms seem to be handled downstream (e.g. in `skipPastExportOrImportSpecifier`), so special-casing the first form
// here appears to be intentional).
- var _a = searchOptions.text, text = _a === void 0 ? ts.stripQuotes(ts.unescapeLeadingUnderscores((ts.getLocalSymbolForExportDefault(symbol) || symbol).escapedName)) : _a, _b = searchOptions.allSearchSymbols, allSearchSymbols = _b === void 0 ? [symbol] : _b;
+ var _a = searchOptions.text, text = _a === void 0 ? ts.stripQuotes(ts.unescapeLeadingUnderscores((ts.getLocalSymbolForExportDefault(symbol) || getNonModuleSymbolOfMergedModuleSymbol(symbol) || symbol).escapedName)) : _a, _b = searchOptions.allSearchSymbols, allSearchSymbols = _b === void 0 ? [symbol] : _b;
var escapedText = ts.escapeLeadingUnderscores(text);
var parents = this.options.implementations && location ? getParentSymbolsOfPropertyAccess(location, symbol, this.checker) : undefined;
return { symbol: symbol, comingFrom: comingFrom, text: text, escapedText: escapedText, parents: parents, allSearchSymbols: allSearchSymbols, includes: function (sym) { return ts.contains(allSearchSymbols, sym); } };
@@ -101131,6 +101317,13 @@ var ts;
if (res2)
return res2;
}
+ var aliasedSymbol = getMergedAliasedSymbolOfNamespaceExportDeclaration(location, symbol, checker);
+ if (aliasedSymbol) {
+ // In case of UMD module and global merging, search for global as well
+ var res_2 = cbSymbol(aliasedSymbol, /*rootSymbol*/ undefined, /*baseSymbol*/ undefined, 1 /* Node */);
+ if (res_2)
+ return res_2;
+ }
var res = fromRoot(symbol);
if (res)
return res;
@@ -101227,7 +101420,8 @@ var ts;
Core.getIntersectingMeaningFromDeclarations = getIntersectingMeaningFromDeclarations;
function isImplementation(node) {
return !!(node.flags & 4194304 /* Ambient */)
- || (ts.isVariableLike(node) ? ts.hasInitializer(node)
+ ? !(ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node))
+ : (ts.isVariableLike(node) ? ts.hasInitializer(node)
: ts.isFunctionLikeDeclaration(node) ? !!node.body
: ts.isClassLike(node) || ts.isModuleOrEnumDeclaration(node));
}
@@ -101385,7 +101579,7 @@ var ts;
}
function updateImports(program, changeTracker, oldToNew, newToOld, host, getCanonicalFileName) {
var allFiles = program.getSourceFiles();
- var _loop_13 = function (sourceFile) {
+ var _loop_14 = function (sourceFile) {
var newFromOld = oldToNew(sourceFile.path);
var newImportFromPath = newFromOld !== undefined ? newFromOld : sourceFile.path;
var newImportFromDirectory = ts.getDirectoryPath(newImportFromPath);
@@ -101417,7 +101611,7 @@ var ts;
};
for (var _i = 0, allFiles_1 = allFiles; _i < allFiles_1.length; _i++) {
var sourceFile = allFiles_1[_i];
- _loop_13(sourceFile);
+ _loop_14(sourceFile);
}
}
function combineNormal(pathA, pathB) {
@@ -102207,7 +102401,7 @@ var ts;
if (!patternMatcher)
return ts.emptyArray;
var rawItems = [];
- var _loop_14 = function (sourceFile) {
+ var _loop_15 = function (sourceFile) {
cancellationToken.throwIfCancellationRequested();
if (excludeDtsFiles && sourceFile.isDeclarationFile) {
return "continue";
@@ -102219,7 +102413,7 @@ var ts;
// Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[]
for (var _i = 0, sourceFiles_6 = sourceFiles; _i < sourceFiles_6.length; _i++) {
var sourceFile = sourceFiles_6[_i];
- _loop_14(sourceFile);
+ _loop_15(sourceFile);
}
rawItems.sort(compareNavigateToItems);
return (maxResultCount === undefined ? rawItems : rawItems.slice(0, maxResultCount)).map(createNavigateToItem);
@@ -103747,13 +103941,13 @@ var ts;
// Assumes 'value' is already lowercase.
function indexOfIgnoringCase(str, value) {
var n = str.length - value.length;
- var _loop_15 = function (start) {
+ var _loop_16 = function (start) {
if (every(value, function (valueChar, i) { return toLowerCase(str.charCodeAt(i + start)) === valueChar; })) {
return { value: start };
}
};
for (var start = 0; start <= n; start++) {
- var state_4 = _loop_15(start);
+ var state_4 = _loop_16(start);
if (typeof state_4 === "object")
return state_4.value;
}
@@ -104766,7 +104960,7 @@ var ts;
return ts.createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart);
}
function getContainingArgumentInfo(node, position, sourceFile, checker, isManuallyInvoked) {
- var _loop_16 = function (n) {
+ var _loop_17 = function (n) {
// If the node is not a subspan of its parent, this is a big problem.
// There have been crashes that might be caused by this violation.
ts.Debug.assert(ts.rangeContainsRange(n.parent, n), "Not a subspan", function () { return "Child: " + ts.Debug.showSyntaxKind(n) + ", parent: " + ts.Debug.showSyntaxKind(n.parent); });
@@ -104775,8 +104969,8 @@ var ts;
return { value: argumentInfo };
}
};
- for (var n = node; isManuallyInvoked || (!ts.isBlock(n) && !ts.isSourceFile(n)); n = n.parent) {
- var state_5 = _loop_16(n);
+ for (var n = node; !ts.isSourceFile(n) && (isManuallyInvoked || !ts.isBlock(n)); n = n.parent) {
+ var state_5 = _loop_17(n);
if (typeof state_5 === "object")
return state_5.value;
}
@@ -105933,7 +106127,7 @@ var ts;
return typeof o.type === "object" && !ts.forEachEntry(o.type, function (v) { return typeof v !== "number"; });
});
options = ts.cloneCompilerOptions(options);
- var _loop_17 = function (opt) {
+ var _loop_18 = function (opt) {
if (!ts.hasProperty(options, opt.name)) {
return "continue";
}
@@ -105952,7 +106146,7 @@ var ts;
};
for (var _i = 0, commandLineOptionsStringToEnum_1 = commandLineOptionsStringToEnum; _i < commandLineOptionsStringToEnum_1.length; _i++) {
var opt = commandLineOptionsStringToEnum_1[_i];
- _loop_17(opt);
+ _loop_18(opt);
}
return options;
}
@@ -109124,7 +109318,7 @@ var ts;
ChangeTracker.prototype.finishDeleteDeclarations = function () {
var _this = this;
var deletedNodesInLists = new ts.NodeSet(); // Stores nodes in lists that we already deleted. Used to avoid deleting `, ` twice in `a, b`.
- var _loop_18 = function (sourceFile, node) {
+ var _loop_19 = function (sourceFile, node) {
if (!this_1.deletedNodes.some(function (d) { return d.sourceFile === sourceFile && ts.rangeContainsRangeExclusive(d.node, node); })) {
if (ts.isArray(node)) {
this_1.deleteRange(sourceFile, ts.rangeOfTypeParameters(node));
@@ -109137,7 +109331,7 @@ var ts;
var this_1 = this;
for (var _i = 0, _a = this.deletedNodes; _i < _a.length; _i++) {
var _b = _a[_i], sourceFile = _b.sourceFile, node = _b.node;
- _loop_18(sourceFile, node);
+ _loop_19(sourceFile, node);
}
deletedNodesInLists.forEach(function (node) {
var sourceFile = node.getSourceFile();
@@ -109194,14 +109388,14 @@ var ts;
// order changes by start position
// If the start position is the same, put the shorter range first, since an empty range (x, x) may precede (x, y) but not vice-versa.
var normalized = ts.stableSort(changesInFile, function (a, b) { return (a.range.pos - b.range.pos) || (a.range.end - b.range.end); });
- var _loop_19 = function (i) {
+ var _loop_20 = function (i) {
ts.Debug.assert(normalized[i].range.end <= normalized[i + 1].range.pos, "Changes overlap", function () {
return JSON.stringify(normalized[i].range) + " and " + JSON.stringify(normalized[i + 1].range);
});
};
// verify that change intervals do not overlap, except possibly at end points.
for (var i = 0; i < normalized.length - 1; i++) {
- _loop_19(i);
+ _loop_20(i);
}
var textChanges = normalized.map(function (c) {
return ts.createTextChange(ts.createTextSpanFromRange(c.range), computeNewText(c, sourceFile, newLineCharacter, formatContext, validate));
@@ -110331,8 +110525,8 @@ var ts;
(function (InferFromReference) {
function inferTypesFromReferences(references, checker, cancellationToken) {
var usageContext = {};
- for (var _i = 0, references_1 = references; _i < references_1.length; _i++) {
- var reference = references_1[_i];
+ for (var _i = 0, references_2 = references; _i < references_2.length; _i++) {
+ var reference = references_2[_i];
cancellationToken.throwIfCancellationRequested();
inferTypeFromContext(reference, checker, usageContext);
}
@@ -110348,8 +110542,8 @@ var ts;
return undefined;
}
var usageContext = {};
- for (var _i = 0, references_2 = references; _i < references_2.length; _i++) {
- var reference = references_2[_i];
+ for (var _i = 0, references_3 = references; _i < references_3.length; _i++) {
+ var reference = references_3[_i];
cancellationToken.throwIfCancellationRequested();
inferTypeFromContext(reference, checker, usageContext);
}
@@ -110989,7 +111183,7 @@ var ts;
var newNodes = transformExpression(node, transformer, node);
changes.replaceNodeWithNodes(sourceFile, nodeToReplace, newNodes);
}
- var _loop_20 = function (statement) {
+ var _loop_21 = function (statement) {
ts.forEachChild(statement, function visit(node) {
if (ts.isCallExpression(node)) {
startTransformation(node, statement);
@@ -111001,7 +111195,7 @@ var ts;
};
for (var _i = 0, returnStatements_1 = returnStatements; _i < returnStatements_1.length; _i++) {
var statement = returnStatements_1[_i];
- _loop_20(statement);
+ _loop_21(statement);
}
}
function getReturnStatementsWithPromiseHandlers(body) {
@@ -112653,7 +112847,7 @@ var ts;
});
typeDeclToMembers.forEach(function (infos, classDeclaration) {
var supers = getAllSupers(classDeclaration, checker);
- var _loop_21 = function (info) {
+ var _loop_22 = function (info) {
// If some superclass added this property, don't add it again.
if (supers.some(function (superClassOrInterface) {
var superInfos = typeDeclToMembers.get(superClassOrInterface);
@@ -112680,7 +112874,7 @@ var ts;
};
for (var _i = 0, infos_1 = infos; _i < infos_1.length; _i++) {
var info = infos_1[_i];
- _loop_21(info);
+ _loop_22(info);
}
});
}));
@@ -113174,6 +113368,32 @@ var ts;
})(ts || (ts = {}));
/* @internal */
var ts;
+(function (ts) {
+ var codefix;
+ (function (codefix) {
+ var fixId = "enableExperimentalDecorators";
+ var errorCodes = [
+ ts.Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_to_remove_this_warning.code
+ ];
+ codefix.registerCodeFix({
+ errorCodes: errorCodes,
+ getCodeActions: function (context) {
+ var configFile = context.program.getCompilerOptions().configFile;
+ if (configFile === undefined) {
+ return undefined;
+ }
+ var changes = ts.textChanges.ChangeTracker.with(context, function (changeTracker) { return makeChange(changeTracker, configFile); });
+ return [codefix.createCodeFixActionNoFixId(fixId, changes, ts.Diagnostics.Enable_the_experimentalDecorators_option_in_your_configuration_file)];
+ },
+ fixIds: [fixId],
+ });
+ function makeChange(changeTracker, configFile) {
+ codefix.setJsonCompilerOptionValue(changeTracker, configFile, "experimentalDecorators", ts.createTrue());
+ }
+ })(codefix = ts.codefix || (ts.codefix = {}));
+})(ts || (ts = {}));
+/* @internal */
+var ts;
(function (ts) {
var codefix;
(function (codefix) {
@@ -114928,7 +115148,7 @@ var ts;
});
var namespaceImportName = namespaceNameConflicts ? ts.getUniqueName(preferredName, sourceFile) : preferredName;
var neededNamedImports = [];
- var _loop_22 = function (element) {
+ var _loop_23 = function (element) {
var propertyName = (element.propertyName || element.name).text;
ts.FindAllReferences.Core.eachSymbolReferenceInFile(element.name, checker, sourceFile, function (id) {
var access = ts.createPropertyAccess(ts.createIdentifier(namespaceImportName), propertyName);
@@ -114947,7 +115167,7 @@ var ts;
};
for (var _i = 0, _a = toConvert.elements; _i < _a.length; _i++) {
var element = _a[_i];
- _loop_22(element);
+ _loop_23(element);
}
changes.replaceNode(sourceFile, toConvert, ts.createNamespaceImport(ts.createIdentifier(namespaceImportName)));
if (neededNamedImports.length) {
@@ -116177,7 +116397,7 @@ var ts;
: ts.getEnclosingBlockScopeContainer(scopes[0]);
ts.forEachChild(containingLexicalScopeOfExtraction, checkForUsedDeclarations);
}
- var _loop_23 = function (i) {
+ var _loop_24 = function (i) {
var scopeUsages = usagesPerScope[i];
// Special case: in the innermost scope, all usages are available.
// (The computed value reflects the value at the top-level of the scope, but the
@@ -116217,7 +116437,7 @@ var ts;
}
};
for (var i = 0; i < scopes.length; i++) {
- _loop_23(i);
+ _loop_24(i);
}
return { target: target, usagesPerScope: usagesPerScope, functionErrorsPerScope: functionErrorsPerScope, constantErrorsPerScope: constantErrorsPerScope, exposedVariableDeclarations: exposedVariableDeclarations };
function isInGenericContext(node) {
@@ -116768,10 +116988,10 @@ var ts;
}
function updateImportsInOtherFiles(changes, program, oldFile, movedSymbols, newModuleName) {
var checker = program.getTypeChecker();
- var _loop_24 = function (sourceFile) {
+ var _loop_25 = function (sourceFile) {
if (sourceFile === oldFile)
return "continue";
- var _loop_25 = function (statement) {
+ var _loop_26 = function (statement) {
forEachImportInStatement(statement, function (importNode) {
if (checker.getSymbolAtLocation(moduleSpecifierFromImport(importNode)) !== oldFile.symbol)
return;
@@ -116793,12 +117013,12 @@ var ts;
};
for (var _i = 0, _a = sourceFile.statements; _i < _a.length; _i++) {
var statement = _a[_i];
- _loop_25(statement);
+ _loop_26(statement);
}
};
for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) {
var sourceFile = _a[_i];
- _loop_24(sourceFile);
+ _loop_25(sourceFile);
}
}
function getNamespaceLikeImport(node) {
@@ -117041,6 +117261,11 @@ var ts;
var movedSymbols = new SymbolSet();
var oldImportsNeededByNewFile = new SymbolSet();
var newFileImportsFromOldFile = new SymbolSet();
+ var containsJsx = ts.find(toMove, function (statement) { return !!(statement.transformFlags & 4 /* ContainsJsx */); });
+ var jsxNamespaceSymbol = getJsxNamespaceSymbol(containsJsx);
+ if (jsxNamespaceSymbol) { // Might not exist (e.g. in non-compiling code)
+ oldImportsNeededByNewFile.add(jsxNamespaceSymbol);
+ }
for (var _i = 0, toMove_1 = toMove; _i < toMove_1.length; _i++) {
var statement = toMove_1[_i];
forEachTopLevelDeclaration(statement, function (decl) {
@@ -117069,6 +117294,10 @@ var ts;
var statement = _c[_b];
if (ts.contains(toMove, statement))
continue;
+ // jsxNamespaceSymbol will only be set iff it is in oldImportsNeededByNewFile.
+ if (jsxNamespaceSymbol && !!(statement.transformFlags & 4 /* ContainsJsx */)) {
+ unusedImportsFromOldFile.delete(jsxNamespaceSymbol);
+ }
forEachReference(statement, checker, function (symbol) {
if (movedSymbols.has(symbol))
oldFileImportsFromNewFile.add(symbol);
@@ -117076,6 +117305,19 @@ var ts;
});
}
return { movedSymbols: movedSymbols, newFileImportsFromOldFile: newFileImportsFromOldFile, oldFileImportsFromNewFile: oldFileImportsFromNewFile, oldImportsNeededByNewFile: oldImportsNeededByNewFile, unusedImportsFromOldFile: unusedImportsFromOldFile };
+ function getJsxNamespaceSymbol(containsJsx) {
+ if (containsJsx === undefined) {
+ return undefined;
+ }
+ var jsxNamespace = checker.getJsxNamespace(containsJsx);
+ // Strictly speaking, this could resolve to a symbol other than the JSX namespace.
+ // This will produce erroneous output (probably, an incorrectly copied import) but
+ // is expected to be very rare and easily reversible.
+ var jsxNamespaceSymbol = checker.resolveName(jsxNamespace, containsJsx, 1920 /* Namespace */, /*excludeGlobals*/ true);
+ return !!jsxNamespaceSymbol && ts.some(jsxNamespaceSymbol.declarations, isInImport)
+ ? jsxNamespaceSymbol
+ : undefined;
+ }
}
// Below should all be utilities
function isInImport(decl) {
@@ -117094,7 +117336,7 @@ var ts;
}
function isVariableDeclarationInImport(decl) {
return ts.isSourceFile(decl.parent.parent.parent) &&
- decl.initializer && ts.isRequireCall(decl.initializer, /*checkArgumentIsStringLiteralLike*/ true);
+ !!decl.initializer && ts.isRequireCall(decl.initializer, /*checkArgumentIsStringLiteralLike*/ true);
}
function filterImport(i, moduleSpecifier, keep) {
switch (i.kind) {
diff --git a/lib/typescriptServices.d.ts b/lib/typescriptServices.d.ts
index e3f3ce42b1933..6cf4178c3f1e5 100644
--- a/lib/typescriptServices.d.ts
+++ b/lib/typescriptServices.d.ts
@@ -1726,15 +1726,18 @@ declare namespace ts {
}
interface InputFiles extends Node {
kind: SyntaxKind.InputFiles;
+ javascriptPath?: string;
javascriptText: string;
javascriptMapPath?: string;
javascriptMapText?: string;
+ declarationPath?: string;
declarationText: string;
declarationMapPath?: string;
declarationMapText?: string;
}
interface UnparsedSource extends Node {
kind: SyntaxKind.UnparsedSource;
+ fileName?: string;
text: string;
sourceMapPath?: string;
sourceMapText?: string;
@@ -2214,6 +2217,7 @@ declare namespace ts {
}
interface UniqueESSymbolType extends Type {
symbol: Symbol;
+ escapedName: __String;
}
interface StringLiteralType extends LiteralType {
value: string;
@@ -3097,6 +3101,7 @@ declare namespace ts {
scanJsxIdentifier(): SyntaxKind;
scanJsxAttributeValue(): SyntaxKind;
reScanJsxToken(): JsxTokenSyntaxKind;
+ reScanLessThanToken(): SyntaxKind;
scanJsxToken(): JsxTokenSyntaxKind;
scanJSDocToken(): JsDocSyntaxKind;
scan(): SyntaxKind;
@@ -3978,9 +3983,11 @@ declare namespace ts {
function updateCommaList(node: CommaListExpression, elements: ReadonlyArray): CommaListExpression;
function createBundle(sourceFiles: ReadonlyArray, prepends?: ReadonlyArray): Bundle;
function createUnparsedSourceFile(text: string): UnparsedSource;
+ function createUnparsedSourceFile(inputFile: InputFiles, type: "js" | "dts"): UnparsedSource;
function createUnparsedSourceFile(text: string, mapPath: string | undefined, map: string | undefined): UnparsedSource;
- function createInputFiles(javascript: string, declaration: string): InputFiles;
- function createInputFiles(javascript: string, declaration: string, javascriptMapPath: string | undefined, javascriptMapText: string | undefined, declarationMapPath: string | undefined, declarationMapText: string | undefined): InputFiles;
+ function createInputFiles(javascriptText: string, declarationText: string): InputFiles;
+ function createInputFiles(readFileText: (path: string) => string | undefined, javascriptPath: string, javascriptMapPath: string | undefined, declarationPath: string, declarationMapPath: string | undefined): InputFiles;
+ function createInputFiles(javascriptText: string, declarationText: string, javascriptMapPath: string | undefined, javascriptMapText: string | undefined, declarationMapPath: string | undefined, declarationMapText: string | undefined): InputFiles;
function updateBundle(node: Bundle, sourceFiles: ReadonlyArray, prepends?: ReadonlyArray): Bundle;
function createImmediatelyInvokedFunctionExpression(statements: ReadonlyArray): CallExpression;
function createImmediatelyInvokedFunctionExpression(statements: ReadonlyArray, param: ParameterDeclaration, paramValue: Expression): CallExpression;
diff --git a/lib/typescriptServices.js b/lib/typescriptServices.js
index 456bf6e54ec06..149e147ccb0b5 100644
--- a/lib/typescriptServices.js
+++ b/lib/typescriptServices.js
@@ -75,7 +75,7 @@ var ts;
// If changing the text in this section, be sure to test `configureNightly` too.
ts.versionMajorMinor = "3.3";
/** The version of the TypeScript compiler release */
- ts.version = ts.versionMajorMinor + ".0-rc";
+ ts.version = ts.versionMajorMinor + ".1";
})(ts || (ts = {}));
(function (ts) {
/* @internal */
@@ -5520,7 +5520,6 @@ var ts;
Property_0_is_used_before_being_assigned: diag(2565, ts.DiagnosticCategory.Error, "Property_0_is_used_before_being_assigned_2565", "Property '{0}' is used before being assigned."),
A_rest_element_cannot_have_a_property_name: diag(2566, ts.DiagnosticCategory.Error, "A_rest_element_cannot_have_a_property_name_2566", "A rest element cannot have a property name."),
Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations: diag(2567, ts.DiagnosticCategory.Error, "Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations_2567", "Enum declarations can only merge with namespace or other enum declarations."),
- Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators: diag(2568, ts.DiagnosticCategory.Error, "Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators_2568", "Type '{0}' is not an array type. Use compiler option '--downlevelIteration' to allow iterating of iterators."),
Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators: diag(2569, ts.DiagnosticCategory.Error, "Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterati_2569", "Type '{0}' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators."),
Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await: diag(2570, ts.DiagnosticCategory.Error, "Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await_2570", "Property '{0}' does not exist on type '{1}'. Did you forget to use 'await'?"),
Object_is_of_type_unknown: diag(2571, ts.DiagnosticCategory.Error, "Object_is_of_type_unknown_2571", "Object is of type 'unknown'."),
@@ -5615,7 +5614,7 @@ var ts;
Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor: diag(2715, ts.DiagnosticCategory.Error, "Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor_2715", "Abstract property '{0}' in class '{1}' cannot be accessed in the constructor."),
Type_parameter_0_has_a_circular_default: diag(2716, ts.DiagnosticCategory.Error, "Type_parameter_0_has_a_circular_default_2716", "Type parameter '{0}' has a circular default."),
Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_type_2: diag(2717, ts.DiagnosticCategory.Error, "Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_t_2717", "Subsequent property declarations must have the same type. Property '{0}' must be of type '{1}', but here has type '{2}'."),
- Duplicate_declaration_0: diag(2718, ts.DiagnosticCategory.Error, "Duplicate_declaration_0_2718", "Duplicate declaration '{0}'."),
+ Duplicate_property_0: diag(2718, ts.DiagnosticCategory.Error, "Duplicate_property_0_2718", "Duplicate property '{0}'."),
Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated: diag(2719, ts.DiagnosticCategory.Error, "Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated_2719", "Type '{0}' is not assignable to type '{1}'. Two different types with this name exist, but they are unrelated."),
Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass: diag(2720, ts.DiagnosticCategory.Error, "Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclas_2720", "Class '{0}' incorrectly implements class '{1}'. Did you mean to extend '{1}' and inherit its members as a subclass?"),
Cannot_invoke_an_object_which_is_possibly_null: diag(2721, ts.DiagnosticCategory.Error, "Cannot_invoke_an_object_which_is_possibly_null_2721", "Cannot invoke an object which is possibly 'null'."),
@@ -5630,6 +5629,7 @@ var ts;
An_arrow_function_cannot_have_a_this_parameter: diag(2730, ts.DiagnosticCategory.Error, "An_arrow_function_cannot_have_a_this_parameter_2730", "An arrow function cannot have a 'this' parameter."),
Implicit_conversion_of_a_symbol_to_a_string_will_fail_at_runtime_Consider_wrapping_this_expression_in_String: diag(2731, ts.DiagnosticCategory.Error, "Implicit_conversion_of_a_symbol_to_a_string_will_fail_at_runtime_Consider_wrapping_this_expression_i_2731", "Implicit conversion of a 'symbol' to a 'string' will fail at runtime. Consider wrapping this expression in 'String(...)'."),
Cannot_find_module_0_Consider_using_resolveJsonModule_to_import_module_with_json_extension: diag(2732, ts.DiagnosticCategory.Error, "Cannot_find_module_0_Consider_using_resolveJsonModule_to_import_module_with_json_extension_2732", "Cannot find module '{0}'. Consider using '--resolveJsonModule' to import module with '.json' extension"),
+ Property_0_was_also_declared_here: diag(2733, ts.DiagnosticCategory.Error, "Property_0_was_also_declared_here_2733", "Property '{0}' was also declared here."),
It_is_highly_likely_that_you_are_missing_a_semicolon: diag(2734, ts.DiagnosticCategory.Error, "It_is_highly_likely_that_you_are_missing_a_semicolon_2734", "It is highly likely that you are missing a semicolon."),
Did_you_mean_for_0_to_be_constrained_to_type_new_args_Colon_any_1: diag(2735, ts.DiagnosticCategory.Error, "Did_you_mean_for_0_to_be_constrained_to_type_new_args_Colon_any_1_2735", "Did you mean for '{0}' to be constrained to type 'new (...args: any[]) => {1}'?"),
Operator_0_cannot_be_applied_to_type_1: diag(2736, ts.DiagnosticCategory.Error, "Operator_0_cannot_be_applied_to_type_1_2736", "Operator '{0}' cannot be applied to type '{1}'."),
@@ -6917,6 +6917,7 @@ var ts;
scanJsxIdentifier: scanJsxIdentifier,
scanJsxAttributeValue: scanJsxAttributeValue,
reScanJsxToken: reScanJsxToken,
+ reScanLessThanToken: reScanLessThanToken,
scanJsxToken: scanJsxToken,
scanJSDocToken: scanJSDocToken,
scan: scan,
@@ -7913,6 +7914,13 @@ var ts;
pos = tokenPos = startPos;
return token = scanJsxToken();
}
+ function reScanLessThanToken() {
+ if (token === 46 /* LessThanLessThanToken */) {
+ pos = tokenPos + 1;
+ return token = 28 /* LessThanToken */;
+ }
+ return token;
+ }
function scanJsxToken() {
startPos = tokenPos = pos;
if (pos >= end) {
@@ -8849,7 +8857,9 @@ var ts;
case 14 /* NoSubstitutionTemplateLiteral */:
return ts.escapeLeadingUnderscores(name.text);
case 149 /* ComputedPropertyName */:
- return isStringOrNumericLiteralLike(name.expression) ? ts.escapeLeadingUnderscores(name.expression.text) : undefined; // TODO: GH#18217 Almost all uses of this assume the result to be defined!
+ if (isStringOrNumericLiteralLike(name.expression))
+ return ts.escapeLeadingUnderscores(name.expression.text);
+ return ts.Debug.fail("Text of property name cannot be read from non-literal-valued ComputedPropertyNames");
default:
return ts.Debug.assertNever(name);
}
@@ -17195,6 +17205,9 @@ var ts;
function reScanTemplateToken() {
return currentToken = scanner.reScanTemplateToken();
}
+ function reScanLessThanToken() {
+ return currentToken = scanner.reScanLessThanToken();
+ }
function scanJsxIdentifier() {
return currentToken = scanner.scanJsxIdentifier();
}
@@ -18206,7 +18219,7 @@ var ts;
function parseTypeReference() {
var node = createNode(164 /* TypeReference */);
node.typeName = parseEntityName(/*allowReservedWords*/ true, ts.Diagnostics.Type_expected);
- if (!scanner.hasPrecedingLineBreak() && token() === 28 /* LessThanToken */) {
+ if (!scanner.hasPrecedingLineBreak() && reScanLessThanToken() === 28 /* LessThanToken */) {
node.typeArguments = parseBracketedList(20 /* TypeArguments */, parseType, 28 /* LessThanToken */, 30 /* GreaterThanToken */);
}
return finishNode(node);
@@ -20228,7 +20241,8 @@ var ts;
function parseCallExpressionRest(expression) {
while (true) {
expression = parseMemberExpressionRest(expression);
- if (token() === 28 /* LessThanToken */) {
+ // handle 'foo<()'
+ if (token() === 28 /* LessThanToken */ || token() === 46 /* LessThanLessThanToken */) {
// See if this is the start of a generic invocation. If so, consume it and
// keep checking for postfix expressions. Otherwise, it's just a '<' that's
// part of an arithmetic expression. Break out so we consume it higher in the
@@ -20265,9 +20279,10 @@ var ts;
return result;
}
function parseTypeArgumentsInExpression() {
- if (!parseOptional(28 /* LessThanToken */)) {
+ if (reScanLessThanToken() !== 28 /* LessThanToken */) {
return undefined;
}
+ nextToken();
var typeArguments = parseDelimitedList(20 /* TypeArguments */, parseType);
if (!parseExpected(30 /* GreaterThanToken */)) {
// If it doesn't have the closing `>` then it's definitely not an type argument list.
@@ -27140,6 +27155,7 @@ var ts;
ContainerFlags[ContainerFlags["IsInterface"] = 64] = "IsInterface";
ContainerFlags[ContainerFlags["IsObjectLiteralOrClassExpressionMethod"] = 128] = "IsObjectLiteralOrClassExpressionMethod";
})(ContainerFlags || (ContainerFlags = {}));
+ var flowNodeCreated = ts.identity;
var binder = createBinder();
function bindSourceFile(file, options) {
ts.performance.mark("beforeBind");
@@ -27528,6 +27544,7 @@ var ts;
blockScopeContainer.locals = undefined;
}
if (containerFlags & 4 /* IsControlFlowContainer */) {
+ var saveFlowNodeCreated = flowNodeCreated;
var saveCurrentFlow = currentFlow;
var saveBreakTarget = currentBreakTarget;
var saveContinueTarget = currentContinueTarget;
@@ -27551,6 +27568,7 @@ var ts;
currentContinueTarget = undefined;
activeLabels = undefined;
hasExplicitReturn = false;
+ flowNodeCreated = ts.identity;
bindChildren(node);
// Reset all reachability check related flags on node (for incremental scenarios)
node.flags &= ~1408 /* ReachabilityAndEmitFlags */;
@@ -27577,6 +27595,7 @@ var ts;
currentReturnTarget = saveReturnTarget;
activeLabels = saveActiveLabels;
hasExplicitReturn = saveHasExplicitReturn;
+ flowNodeCreated = saveFlowNodeCreated;
}
else if (containerFlags & 64 /* IsInterface */) {
seenThisKeyword = false;
@@ -27840,22 +27859,22 @@ var ts;
return antecedent;
}
setFlowNodeReferenced(antecedent);
- return { flags: flags, expression: expression, antecedent: antecedent };
+ return flowNodeCreated({ flags: flags, expression: expression, antecedent: antecedent });
}
function createFlowSwitchClause(antecedent, switchStatement, clauseStart, clauseEnd) {
if (!isNarrowingExpression(switchStatement.expression)) {
return antecedent;
}
setFlowNodeReferenced(antecedent);
- return { flags: 128 /* SwitchClause */, switchStatement: switchStatement, clauseStart: clauseStart, clauseEnd: clauseEnd, antecedent: antecedent };
+ return flowNodeCreated({ flags: 128 /* SwitchClause */, switchStatement: switchStatement, clauseStart: clauseStart, clauseEnd: clauseEnd, antecedent: antecedent });
}
function createFlowAssignment(antecedent, node) {
setFlowNodeReferenced(antecedent);
- return { flags: 16 /* Assignment */, antecedent: antecedent, node: node };
+ return flowNodeCreated({ flags: 16 /* Assignment */, antecedent: antecedent, node: node });
}
function createFlowArrayMutation(antecedent, node) {
setFlowNodeReferenced(antecedent);
- var res = { flags: 256 /* ArrayMutation */, antecedent: antecedent, node: node };
+ var res = flowNodeCreated({ flags: 256 /* ArrayMutation */, antecedent: antecedent, node: node });
return res;
}
function finishFlowLabel(flow) {
@@ -28043,18 +28062,46 @@ var ts;
function bindTryStatement(node) {
var preFinallyLabel = createBranchLabel();
var preTryFlow = currentFlow;
- // TODO: Every statement in try block is potentially an exit point!
+ var tryPriors = [];
+ var oldFlowNodeCreated = flowNodeCreated;
+ // We hook the creation of all flow nodes within the `try` scope and store them so we can add _all_ of them
+ // as possible antecedents of the start of the `catch` or `finally` blocks.
+ // Don't bother intercepting the call if there's no finally or catch block that needs the information
+ if (node.catchClause || node.finallyBlock) {
+ flowNodeCreated = function (node) { return (tryPriors.push(node), node); };
+ }
bind(node.tryBlock);
+ flowNodeCreated = oldFlowNodeCreated;
addAntecedent(preFinallyLabel, currentFlow);
var flowAfterTry = currentFlow;
var flowAfterCatch = unreachableFlow;
if (node.catchClause) {
currentFlow = preTryFlow;
+ if (tryPriors.length) {
+ var preCatchFlow = createBranchLabel();
+ addAntecedent(preCatchFlow, currentFlow);
+ for (var _i = 0, tryPriors_1 = tryPriors; _i < tryPriors_1.length; _i++) {
+ var p = tryPriors_1[_i];
+ addAntecedent(preCatchFlow, p);
+ }
+ currentFlow = finishFlowLabel(preCatchFlow);
+ }
bind(node.catchClause);
addAntecedent(preFinallyLabel, currentFlow);
flowAfterCatch = currentFlow;
}
if (node.finallyBlock) {
+ // We add the nodes within the `try` block to the `finally`'s antecedents if there's no catch block
+ // (If there is a `catch` block, it will have all these antecedents instead, and the `finally` will
+ // have the end of the `try` block and the end of the `catch` block)
+ if (!node.catchClause) {
+ if (tryPriors.length) {
+ for (var _a = 0, tryPriors_2 = tryPriors; _a < tryPriors_2.length; _a++) {
+ var p = tryPriors_2[_a];
+ addAntecedent(preFinallyLabel, p);
+ }
+ }
+ }
// in finally flow is combined from pre-try/flow from try/flow from catch
// pre-flow is necessary to make sure that finally is reachable even if finally flows in both try and finally blocks are unreachable
// also for finally blocks we inject two extra edges into the flow graph.
@@ -28099,7 +28146,7 @@ var ts;
}
}
if (!(currentFlow.flags & 1 /* Unreachable */)) {
- var afterFinallyFlow = { flags: 4096 /* AfterFinally */, antecedent: currentFlow };
+ var afterFinallyFlow = flowNodeCreated({ flags: 4096 /* AfterFinally */, antecedent: currentFlow });
preFinallyFlow.lock = afterFinallyFlow;
currentFlow = afterFinallyFlow;
}
@@ -35625,16 +35672,17 @@ var ts;
var objectFlags = 128 /* ObjectLiteral */;
ts.forEach(pattern.elements, function (e) {
var name = e.propertyName || e.name;
- if (isComputedNonLiteralName(name)) {
- // do not include computed properties in the implied type
- objectFlags |= 512 /* ObjectLiteralPatternWithComputedProperties */;
- return;
- }
if (e.dotDotDotToken) {
stringIndexInfo = createIndexInfo(anyType, /*isReadonly*/ false);
return;
}
- var text = ts.getTextOfPropertyName(name);
+ var exprType = getLiteralTypeFromPropertyName(name);
+ if (!isTypeUsableAsPropertyName(exprType)) {
+ // do not include computed properties in the implied type
+ objectFlags |= 512 /* ObjectLiteralPatternWithComputedProperties */;
+ return;
+ }
+ var text = getPropertyNameFromType(exprType);
var flags = 4 /* Property */ | (e.initializer ? 16777216 /* Optional */ : 0);
var symbol = createSymbol(flags, text);
symbol.type = getTypeFromBindingElement(e, includePatternInType, reportErrors);
@@ -36676,9 +36724,9 @@ var ts;
return type;
}
/**
- * Indicates whether a type can be used as a late-bound name.
+ * Indicates whether a type can be used as a property name.
*/
- function isTypeUsableAsLateBoundName(type) {
+ function isTypeUsableAsPropertyName(type) {
return !!(type.flags & 8576 /* StringOrNumberLiteralOrUnique */);
}
/**
@@ -36692,7 +36740,7 @@ var ts;
function isLateBindableName(node) {
return ts.isComputedPropertyName(node)
&& ts.isEntityNameExpression(node.expression)
- && isTypeUsableAsLateBoundName(checkComputedPropertyName(node));
+ && isTypeUsableAsPropertyName(checkComputedPropertyName(node));
}
function isLateBoundName(name) {
return name.charCodeAt(0) === 95 /* _ */ &&
@@ -36719,11 +36767,11 @@ var ts;
return ts.isDynamicName(node) && !isLateBindableName(node);
}
/**
- * Gets the symbolic name for a late-bound member from its type.
+ * Gets the symbolic name for a member from its type.
*/
- function getLateBoundNameFromType(type) {
+ function getPropertyNameFromType(type) {
if (type.flags & 8192 /* UniqueESSymbol */) {
- return "__@" + type.symbol.escapedName + "@" + getSymbolId(type.symbol);
+ return type.escapedName;
}
if (type.flags & (128 /* StringLiteral */ | 256 /* NumberLiteral */)) {
return ts.escapeLeadingUnderscores("" + type.value);
@@ -36787,8 +36835,8 @@ var ts;
// fall back to the early-bound name of this member.
links.resolvedSymbol = decl.symbol;
var type = checkComputedPropertyName(decl.name);
- if (isTypeUsableAsLateBoundName(type)) {
- var memberName = getLateBoundNameFromType(type);
+ if (isTypeUsableAsPropertyName(type)) {
+ var memberName = getPropertyNameFromType(type);
var symbolFlags = decl.symbol.flags;
// Get or add a late-bound symbol for the member. This allows us to merge late-bound accessor declarations.
var lateSymbol = lateSymbols.get(memberName);
@@ -36802,9 +36850,9 @@ var ts;
// If we have an existing early-bound member, combine its declarations so that we can
// report an error at each declaration.
var declarations = earlySymbol ? ts.concatenate(earlySymbol.declarations, lateSymbol.declarations) : lateSymbol.declarations;
- var name_3 = ts.declarationNameToString(decl.name);
- ts.forEach(declarations, function (declaration) { return error(ts.getNameOfDeclaration(declaration) || declaration, ts.Diagnostics.Duplicate_declaration_0, name_3); });
- error(decl.name || decl, ts.Diagnostics.Duplicate_declaration_0, name_3);
+ var name_3 = !(type.flags & 8192 /* UniqueESSymbol */) && ts.unescapeLeadingUnderscores(memberName) || ts.declarationNameToString(decl.name);
+ ts.forEach(declarations, function (declaration) { return error(ts.getNameOfDeclaration(declaration) || declaration, ts.Diagnostics.Property_0_was_also_declared_here, name_3); });
+ error(decl.name || decl, ts.Diagnostics.Duplicate_property_0, name_3);
lateSymbol = createSymbol(0 /* None */, memberName, 2048 /* Late */);
}
lateSymbol.nameType = type;
@@ -37396,8 +37444,8 @@ var ts;
var propType = instantiateType(templateType, templateMapper);
// If the current iteration type constituent is a string literal type, create a property.
// Otherwise, for type string create a string index signature.
- if (t.flags & 8576 /* StringOrNumberLiteralOrUnique */) {
- var propName = getLateBoundNameFromType(t);
+ if (isTypeUsableAsPropertyName(t)) {
+ var propName = getPropertyNameFromType(t);
var modifiersProp = getPropertyOfType(modifiersType, propName);
var isOptional = !!(templateModifiers & 4 /* IncludeOptional */ ||
!(templateModifiers & 8 /* ExcludeOptional */) && modifiersProp && modifiersProp.flags & 16777216 /* Optional */);
@@ -37567,7 +37615,8 @@ var ts;
function isTypeInvalidDueToUnionDiscriminant(contextualType, obj) {
var list = obj.properties;
return list.some(function (property) {
- var name = property.name && ts.getTextOfPropertyName(property.name);
+ var nameType = property.name && getLiteralTypeFromPropertyName(property.name);
+ var name = nameType && isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined;
var expected = name === undefined ? undefined : getTypeOfPropertyOfType(contextualType, name);
return !!expected && isLiteralType(expected) && !isTypeIdenticalTo(getTypeOfNode(property), expected);
});
@@ -37937,6 +37986,10 @@ var ts;
result.containingType = containingType;
if (!hasNonUniformValueDeclaration && firstValueDeclaration) {
result.valueDeclaration = firstValueDeclaration;
+ // Inherit information about parent type.
+ if (firstValueDeclaration.symbol.parent) {
+ result.parent = firstValueDeclaration.symbol.parent;
+ }
}
result.declarations = declarations;
result.nameType = nameType;
@@ -38795,21 +38848,16 @@ var ts;
* the type of this reference is just the type of the value we resolved to.
*/
function getJSDocTypeReference(node, symbol, typeArguments) {
- if (!pushTypeResolution(symbol, 6 /* JSDocTypeReference */)) {
- return errorType;
- }
- var assignedType = getAssignedClassType(symbol);
- var valueType = getTypeOfSymbol(symbol);
- var referenceType = valueType.symbol && valueType.symbol !== symbol && !isInferredClassType(valueType) && getTypeReferenceTypeWorker(node, valueType.symbol, typeArguments);
- if (!popTypeResolution()) {
- getSymbolLinks(symbol).resolvedJSDocType = errorType;
- error(node, ts.Diagnostics.JSDoc_type_0_circularly_references_itself, symbolToString(symbol));
- return errorType;
- }
- if (referenceType || assignedType) {
- // TODO: GH#18217 (should the `|| assignedType` be at a lower precedence?)
- var type = (referenceType && assignedType ? getIntersectionType([assignedType, referenceType]) : referenceType || assignedType);
- return getSymbolLinks(symbol).resolvedJSDocType = type;
+ // In the case of an assignment of a function expression (binary expressions, variable declarations, etc.), we will get the
+ // correct instance type for the symbol on the LHS by finding the type for RHS. For example if we want to get the type of the symbol `foo`:
+ // var foo = function() {}
+ // We will find the static type of the assigned anonymous function.
+ var staticType = getTypeOfSymbol(symbol);
+ var instanceType = staticType.symbol &&
+ staticType.symbol !== symbol && // Make sure this is an assignment like expression by checking that symbol -> type -> symbol doesn't roundtrips.
+ getTypeReferenceTypeWorker(node, staticType.symbol, typeArguments); // Get the instance type of the RHS symbol.
+ if (instanceType) {
+ return getSymbolLinks(symbol).resolvedJSDocType = instanceType;
}
}
function getTypeReferenceTypeWorker(node, symbol, typeArguments) {
@@ -38827,8 +38875,11 @@ var ts;
}
if (symbol.flags & 16 /* Function */ &&
isJSDocTypeReference(node) &&
- (symbol.members || ts.getJSDocClassTag(symbol.valueDeclaration))) {
- return getInferredClassType(symbol);
+ isJSConstructor(symbol.valueDeclaration)) {
+ var resolved = resolveStructuredTypeMembers(getTypeOfSymbol(symbol));
+ if (resolved.callSignatures.length === 1) {
+ return getReturnTypeOfSignature(resolved.callSignatures[0]);
+ }
}
}
function getSubstitutionType(typeVariable, substitute) {
@@ -39725,8 +39776,8 @@ var ts;
}
function getPropertyTypeForIndexType(objectType, indexType, accessNode, cacheSymbol, missingType) {
var accessExpression = accessNode && accessNode.kind === 190 /* ElementAccessExpression */ ? accessNode : undefined;
- var propName = isTypeUsableAsLateBoundName(indexType) ?
- getLateBoundNameFromType(indexType) :
+ var propName = isTypeUsableAsPropertyName(indexType) ?
+ getPropertyNameFromType(indexType) :
accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ?
ts.getPropertyNameForKnownSymbolName(ts.idText(accessExpression.argumentExpression.name)) :
accessNode && ts.isPropertyName(accessNode) ?
@@ -40370,6 +40421,7 @@ var ts;
function createUniqueESSymbolType(symbol) {
var type = createType(8192 /* UniqueESSymbol */);
type.symbol = symbol;
+ type.escapedName = "__@" + type.symbol.escapedName + "@" + getSymbolId(type.symbol);
return type;
}
function getESSymbolLikeTypeForNode(node) {
@@ -40567,7 +40619,9 @@ var ts;
return type.flags & 262144 /* TypeParameter */ ? wildcardType : type;
}
function getRestrictiveTypeParameter(tp) {
- return !tp.constraint ? tp : tp.restrictiveInstantiation || (tp.restrictiveInstantiation = createTypeParameter(tp.symbol));
+ return tp.constraint === unknownType ? tp : tp.restrictiveInstantiation || (tp.restrictiveInstantiation = createTypeParameter(tp.symbol),
+ tp.restrictiveInstantiation.constraint = unknownType,
+ tp.restrictiveInstantiation);
}
function restrictiveMapper(type) {
return type.flags & 262144 /* TypeParameter */ ? getRestrictiveTypeParameter(type) : type;
@@ -41182,7 +41236,7 @@ var ts;
}
if (resultObj.error) {
var reportedDiag = resultObj.error;
- var propertyName = isTypeUsableAsLateBoundName(nameType) ? getLateBoundNameFromType(nameType) : undefined;
+ var propertyName = isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined;
var targetProp = propertyName !== undefined ? getPropertyOfType(target, propertyName) : undefined;
var issuedElaboration = false;
if (!targetProp) {
@@ -42538,7 +42592,7 @@ var ts;
}
else {
// An empty object type is related to any mapped type that includes a '?' modifier.
- if (isPartialMappedType(target) && isEmptyObjectType(source)) {
+ if (relation !== subtypeRelation && isPartialMappedType(target) && isEmptyObjectType(source)) {
return -1 /* True */;
}
if (isGenericMappedType(target)) {
@@ -44342,7 +44396,11 @@ var ts;
priority |= 4 /* MappedTypeConstraint */;
inferFromTypes(getIndexType(source), constraintType);
priority = savePriority;
- inferFromTypes(getUnionType(ts.map(getPropertiesOfType(source), getTypeOfSymbol)), getTemplateTypeFromMappedType(target));
+ var valueTypes = ts.compact([
+ getIndexTypeOfType(source, 0 /* String */),
+ getIndexTypeOfType(source, 1 /* Number */)
+ ].concat(ts.map(getPropertiesOfType(source), getTypeOfSymbol)));
+ inferFromTypes(getUnionType(valueTypes), getTemplateTypeFromMappedType(target));
return true;
}
return false;
@@ -44899,7 +44957,10 @@ var ts;
return type;
}
function getTypeOfDestructuredProperty(type, name) {
- var text = ts.getTextOfPropertyName(name);
+ var nameType = getLiteralTypeFromPropertyName(name);
+ if (!isTypeUsableAsPropertyName(nameType))
+ return errorType;
+ var text = getPropertyNameFromType(nameType);
return getConstraintForLocation(getTypeOfPropertyOfType(type, text), name) ||
isNumericLiteralName(text) && getIndexTypeOfType(type, 1 /* Number */) ||
getIndexTypeOfType(type, 0 /* String */) ||
@@ -45457,9 +45518,6 @@ var ts;
}
function getTypeAtSwitchClause(flow) {
var expr = flow.switchStatement.expression;
- if (containsMatchingReferenceDiscriminant(reference, expr)) {
- return declaredType;
- }
var flowType = getTypeAtFlowNode(flow.antecedent);
var type = getTypeFromFlowType(flowType);
if (isMatchingReference(reference, expr)) {
@@ -45471,6 +45529,9 @@ var ts;
else if (expr.kind === 199 /* TypeOfExpression */ && isMatchingReference(reference, expr.expression)) {
type = narrowBySwitchOnTypeOf(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd);
}
+ else if (containsMatchingReferenceDiscriminant(reference, expr)) {
+ type = declaredType;
+ }
return createFlowType(type, isIncomplete(flowType));
}
function getTypeAtFlowBranchLabel(flow) {
@@ -46463,7 +46524,7 @@ var ts;
else if (isInJS &&
(container.kind === 196 /* FunctionExpression */ || container.kind === 239 /* FunctionDeclaration */) &&
ts.getJSDocClassTag(container)) {
- var classType = getJSClassType(container.symbol);
+ var classType = getJSClassType(getMergedSymbol(container.symbol));
if (classType) {
return getFlowTypeOfReference(node, classType);
}
@@ -46858,9 +46919,10 @@ var ts;
var parentDeclaration = declaration.parent.parent;
var name = declaration.propertyName || declaration.name;
var parentType = getContextualTypeForVariableLikeDeclaration(parentDeclaration);
- if (parentType && !ts.isBindingPattern(name)) {
- var text = ts.getTextOfPropertyName(name);
- if (text !== undefined) {
+ if (parentType && !ts.isBindingPattern(name) && !isComputedNonLiteralName(name)) {
+ var nameType = getLiteralTypeFromPropertyName(name);
+ if (isTypeUsableAsPropertyName(nameType)) {
+ var text = getPropertyNameFromType(nameType);
return getTypeOfPropertyOfType(parentType, text);
}
}
@@ -47734,10 +47796,9 @@ var ts;
}
}
typeFlags |= type.flags;
- var nameType = computedNameType && computedNameType.flags & 8576 /* StringOrNumberLiteralOrUnique */ ?
- computedNameType : undefined;
+ var nameType = computedNameType && isTypeUsableAsPropertyName(computedNameType) ? computedNameType : undefined;
var prop = nameType ?
- createSymbol(4 /* Property */ | member.flags, getLateBoundNameFromType(nameType), 2048 /* Late */) :
+ createSymbol(4 /* Property */ | member.flags, getPropertyNameFromType(nameType), 2048 /* Late */) :
createSymbol(4 /* Property */ | member.flags, member.escapedName);
if (nameType) {
prop.nameType = nameType;
@@ -47995,6 +48056,10 @@ var ts;
childrenPropSymbol.type = childrenTypes.length === 1 ?
childrenTypes[0] :
(getArrayLiteralTupleTypeIfApplicable(childrenTypes, childrenContextualType, /*hasRestElement*/ false) || createArrayType(getUnionType(childrenTypes)));
+ // Fake up a property declaration for the children
+ childrenPropSymbol.valueDeclaration = ts.createPropertySignature(/*modifiers*/ undefined, ts.unescapeLeadingUnderscores(jsxChildrenPropertyName), /*questionToken*/ undefined, /*type*/ undefined, /*initializer*/ undefined);
+ childrenPropSymbol.valueDeclaration.parent = attributes;
+ childrenPropSymbol.valueDeclaration.symbol = childrenPropSymbol;
var childPropMap = ts.createSymbolTable();
childPropMap.set(jsxChildrenPropertyName, childrenPropSymbol);
spread = getSpreadType(spread, createAnonymousType(attributes.symbol, childPropMap, ts.emptyArray, ts.emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined), attributes.symbol, typeFlags, objectFlags);
@@ -49674,6 +49739,12 @@ var ts;
if (inferenceContext) {
var typeArgumentTypes = inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext);
checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration));
+ // If the original signature has a generic rest type, instantiation may produce a
+ // signature with different arity and we need to perform another arity check.
+ if (getNonArrayRestType(candidate) && !hasCorrectArity(node, args, checkCandidate, signatureHelpTrailingComma)) {
+ candidateForArgumentArityError = checkCandidate;
+ continue;
+ }
}
if (!checkApplicableSignature(node, args, checkCandidate, relation, excludeArgument, /*reportErrors*/ false)) {
// Give preference to error candidates that have no rest parameters (as they are more specific)
@@ -50225,7 +50296,7 @@ var ts;
return true;
// If the symbol of the node has members, treat it like a constructor.
var symbol = getSymbolOfNode(func);
- return !!symbol && symbol.members !== undefined;
+ return !!symbol && (symbol.members !== undefined || symbol.exports !== undefined && symbol.exports.get("prototype") !== undefined);
}
return false;
}
@@ -50242,10 +50313,6 @@ var ts;
inferred = getInferredClassType(symbol);
}
var assigned = getAssignedClassType(symbol);
- var valueType = getTypeOfSymbol(symbol);
- if (valueType.symbol && !isInferredClassType(valueType) && isJSConstructor(valueType.symbol.valueDeclaration)) {
- inferred = getInferredClassType(valueType.symbol);
- }
return assigned && inferred ?
getIntersectionType([inferred, assigned]) :
assigned || inferred;
@@ -50280,11 +50347,6 @@ var ts;
}
return links.inferredClassType;
}
- function isInferredClassType(type) {
- return type.symbol
- && ts.getObjectFlags(type) & 16 /* Anonymous */
- && getSymbolLinks(type.symbol).inferredClassType === type;
- }
/**
* Syntactically and semantically checks a call or new expression.
* @param node The call/new expression to be checked.
@@ -50303,20 +50365,9 @@ var ts;
declaration.kind !== 157 /* Constructor */ &&
declaration.kind !== 161 /* ConstructSignature */ &&
declaration.kind !== 166 /* ConstructorType */ &&
- !ts.isJSDocConstructSignature(declaration)) {
- // When resolved signature is a call signature (and not a construct signature) the result type is any, unless
- // the declaring function had members created through 'x.prototype.y = expr' or 'this.y = expr' psuedodeclarations
- // in a JS file
- // Note:JS inferred classes might come from a variable declaration instead of a function declaration.
- // In this case, using getResolvedSymbol directly is required to avoid losing the members from the declaration.
- var funcSymbol = checkExpression(node.expression).symbol;
- if (!funcSymbol && node.expression.kind === 72 /* Identifier */) {
- funcSymbol = getResolvedSymbol(node.expression);
- }
- var type = funcSymbol && getJSClassType(funcSymbol);
- if (type) {
- return signature.target ? instantiateType(type, signature.mapper) : type;
- }
+ !ts.isJSDocConstructSignature(declaration) &&
+ !isJSConstructor(declaration)) {
+ // When resolved signature is a call signature (and not a construct signature) the result type is any
if (noImplicitAny) {
error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type);
}
@@ -51371,7 +51422,7 @@ var ts;
if (!(isTypeComparableTo(leftType, stringType) || isTypeAssignableToKind(leftType, 296 /* NumberLike */ | 12288 /* ESSymbolLike */))) {
error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol);
}
- if (!isTypeAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */)) {
+ if (!allTypesAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */)) {
error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
}
return booleanType;
@@ -51392,15 +51443,15 @@ var ts;
if (rightIsThis === void 0) { rightIsThis = false; }
if (property.kind === 275 /* PropertyAssignment */ || property.kind === 276 /* ShorthandPropertyAssignment */) {
var name = property.name;
- var text = ts.getTextOfPropertyName(name);
- if (text) {
+ var exprType = getLiteralTypeFromPropertyName(name);
+ if (isTypeUsableAsPropertyName(exprType)) {
+ var text = getPropertyNameFromType(exprType);
var prop = getPropertyOfType(objectLiteralType, text);
if (prop) {
markPropertyAsReferenced(prop, property, rightIsThis);
checkPropertyAccessibility(property, /*isSuper*/ false, objectLiteralType, prop);
}
}
- var exprType = getLiteralTypeFromPropertyName(name);
var elementType = getIndexedAccessType(objectLiteralType, exprType, name);
var type = getFlowTypeOfDestructuring(property, elementType);
return checkDestructuringAssignment(property.kind === 276 /* ShorthandPropertyAssignment */ ? property : property.initializer, type);
@@ -54390,10 +54441,11 @@ var ts;
var parent = node.parent.parent;
var parentType = getTypeForBindingElementParent(parent);
var name = node.propertyName || node.name;
- if (!ts.isBindingPattern(name)) {
- var nameText = ts.getTextOfPropertyName(name);
- if (nameText) {
- var property = getPropertyOfType(parentType, nameText); // TODO: GH#18217
+ if (!ts.isBindingPattern(name) && parentType) {
+ var exprType = getLiteralTypeFromPropertyName(name);
+ if (isTypeUsableAsPropertyName(exprType)) {
+ var nameText = getPropertyNameFromType(exprType);
+ var property = getPropertyOfType(parentType, nameText);
if (property) {
markPropertyAsReferenced(property, /*nodeForCheckWriteOnly*/ undefined, /*isThisAccess*/ false); // A destructuring is never a write-only reference.
checkPropertyAccessibility(parent, !!parent.initializer && parent.initializer.kind === 98 /* SuperKeyword */, parentType, property);
@@ -54750,7 +54802,7 @@ var ts;
? downlevelIteration
? ts.Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator
: isIterable
- ? ts.Diagnostics.Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators
+ ? ts.Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators
: ts.Diagnostics.Type_0_is_not_an_array_type
: downlevelIteration
? ts.Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator
@@ -59392,6 +59444,7 @@ var ts;
if (nodeArguments.length !== 1) {
return grammarErrorOnNode(node, ts.Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument);
}
+ checkGrammarForDisallowedTrailingComma(nodeArguments);
// see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import.
// parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import.
if (ts.isSpreadElement(nodeArguments[0])) {
@@ -61824,22 +61877,62 @@ var ts;
return node;
}
ts.createBundle = createBundle;
- function createUnparsedSourceFile(text, mapPath, map) {
+ function createUnparsedSourceFile(textOrInputFiles, mapPathOrType, map) {
var node = ts.createNode(281 /* UnparsedSource */);
- node.text = text;
- node.sourceMapPath = mapPath;
- node.sourceMapText = map;
+ if (!ts.isString(textOrInputFiles)) {
+ ts.Debug.assert(mapPathOrType === "js" || mapPathOrType === "dts");
+ node.fileName = mapPathOrType === "js" ? textOrInputFiles.javascriptPath : textOrInputFiles.declarationPath;
+ node.sourceMapPath = mapPathOrType === "js" ? textOrInputFiles.javascriptMapPath : textOrInputFiles.declarationMapPath;
+ Object.defineProperties(node, {
+ text: { get: function () { return mapPathOrType === "js" ? textOrInputFiles.javascriptText : textOrInputFiles.declarationText; } },
+ sourceMapText: { get: function () { return mapPathOrType === "js" ? textOrInputFiles.javascriptMapText : textOrInputFiles.declarationMapText; } },
+ });
+ }
+ else {
+ node.text = textOrInputFiles;
+ node.sourceMapPath = mapPathOrType;
+ node.sourceMapText = map;
+ }
return node;
}
ts.createUnparsedSourceFile = createUnparsedSourceFile;
- function createInputFiles(javascript, declaration, javascriptMapPath, javascriptMapText, declarationMapPath, declarationMapText) {
+ function createInputFiles(javascriptTextOrReadFileText, declarationTextOrJavascriptPath, javascriptMapPath, javascriptMapTextOrDeclarationPath, declarationMapPath, declarationMapText) {
var node = ts.createNode(282 /* InputFiles */);
- node.javascriptText = javascript;
- node.javascriptMapPath = javascriptMapPath;
- node.javascriptMapText = javascriptMapText;
- node.declarationText = declaration;
- node.declarationMapPath = declarationMapPath;
- node.declarationMapText = declarationMapText;
+ if (!ts.isString(javascriptTextOrReadFileText)) {
+ var cache_1 = ts.createMap();
+ var textGetter_1 = function (path) {
+ if (path === undefined)
+ return undefined;
+ var value = cache_1.get(path);
+ if (value === undefined) {
+ value = javascriptTextOrReadFileText(path);
+ cache_1.set(path, value !== undefined ? value : false);
+ }
+ return value !== false ? value : undefined;
+ };
+ var definedTextGetter_1 = function (path) {
+ var result = textGetter_1(path);
+ return result !== undefined ? result : "/* Input file " + path + " was missing */\r\n";
+ };
+ node.javascriptPath = declarationTextOrJavascriptPath;
+ node.javascriptMapPath = javascriptMapPath;
+ node.declarationPath = ts.Debug.assertDefined(javascriptMapTextOrDeclarationPath);
+ node.declarationMapPath = declarationMapPath;
+ Object.defineProperties(node, {
+ javascriptText: { get: function () { return definedTextGetter_1(declarationTextOrJavascriptPath); } },
+ javascriptMapText: { get: function () { return textGetter_1(javascriptMapPath); } },
+ declarationText: { get: function () { return definedTextGetter_1(ts.Debug.assertDefined(javascriptMapTextOrDeclarationPath)); } },
+ declarationMapText: { get: function () { return textGetter_1(declarationMapPath); } } // TODO:: if there is inline sourceMap in dtsFile, use that
+ });
+ }
+ else {
+ node.javascriptText = javascriptTextOrReadFileText;
+ node.javascriptMapPath = javascriptMapPath;
+ node.javascriptMapText = javascriptMapTextOrDeclarationPath;
+ node.declarationText = declarationTextOrJavascriptPath;
+ node.declarationMapPath = declarationMapPath;
+ node.declarationMapText = declarationMapText;
+ }
return node;
}
ts.createInputFiles = createInputFiles;
@@ -66190,7 +66283,7 @@ var ts;
function transformBundle(node) {
return ts.createBundle(node.sourceFiles.map(transformSourceFile), ts.mapDefined(node.prepends, function (prepend) {
if (prepend.kind === 282 /* InputFiles */) {
- return ts.createUnparsedSourceFile(prepend.javascriptText, prepend.javascriptMapPath, prepend.javascriptMapText);
+ return ts.createUnparsedSourceFile(prepend, "js");
}
return prepend;
}));
@@ -80423,7 +80516,7 @@ var ts;
return ts.updateSourceFileNode(sourceFile, transformAndReplaceLatePaintedStatements(updated), /*isDeclarationFile*/ true, /*referencedFiles*/ [], /*typeReferences*/ [], /*hasNoDefaultLib*/ false, /*libReferences*/ []);
}), ts.mapDefined(node.prepends, function (prepend) {
if (prepend.kind === 282 /* InputFiles */) {
- return ts.createUnparsedSourceFile(prepend.declarationText, prepend.declarationMapPath, prepend.declarationMapText);
+ return ts.createUnparsedSourceFile(prepend, "dts");
}
}));
bundle.syntheticFileReferences = [];
@@ -81784,16 +81877,21 @@ var ts;
}
ts.forEachEmittedFile = forEachEmittedFile;
/*@internal*/
+ function getOutputPathsForBundle(options, forceDtsPaths) {
+ var outPath = options.outFile || options.out;
+ var jsFilePath = options.emitDeclarationOnly ? undefined : outPath;
+ var sourceMapFilePath = jsFilePath && getSourceMapFilePath(jsFilePath, options);
+ var declarationFilePath = (forceDtsPaths || ts.getEmitDeclarations(options)) ? ts.removeFileExtension(outPath) + ".d.ts" /* Dts */ : undefined;
+ var declarationMapPath = declarationFilePath && ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
+ var bundleInfoPath = options.references && jsFilePath ? (ts.removeFileExtension(jsFilePath) + infoExtension) : undefined;
+ return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: bundleInfoPath };
+ }
+ ts.getOutputPathsForBundle = getOutputPathsForBundle;
+ /*@internal*/
function getOutputPathsFor(sourceFile, host, forceDtsPaths) {
var options = host.getCompilerOptions();
if (sourceFile.kind === 280 /* Bundle */) {
- var outPath = options.outFile || options.out;
- var jsFilePath = options.emitDeclarationOnly ? undefined : outPath;
- var sourceMapFilePath = jsFilePath && getSourceMapFilePath(jsFilePath, options);
- var declarationFilePath = (forceDtsPaths || ts.getEmitDeclarations(options)) ? ts.removeFileExtension(outPath) + ".d.ts" /* Dts */ : undefined;
- var declarationMapPath = declarationFilePath && ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
- var bundleInfoPath = options.references && jsFilePath ? (ts.removeFileExtension(jsFilePath) + infoExtension) : undefined;
- return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: bundleInfoPath };
+ return getOutputPathsForBundle(options, forceDtsPaths);
}
else {
var ownOutputFilePath = ts.getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options));
@@ -85588,10 +85686,10 @@ var ts;
}
}
/**
- * Skips trivia such as comments and white-space that can optionally overriden by the source map source
+ * Skips trivia such as comments and white-space that can be optionally overridden by the source-map source
*/
function skipSourceTrivia(source, pos) {
- return source.skipTrivia ? source.skipTrivia(pos) : ts.skipTrivia(sourceMapSource.text, pos);
+ return source.skipTrivia ? source.skipTrivia(pos) : ts.skipTrivia(source.text, pos);
}
/**
* Emits a mapping.
@@ -87262,14 +87360,12 @@ var ts;
// Upstream project didn't have outFile set -- skip (error will have been issued earlier)
if (!out)
continue;
- var dtsFilename = ts.changeExtension(out, ".d.ts");
- var js = host.readFile(out) || "/* Input file " + out + " was missing */\r\n";
- var jsMapPath = out + ".map"; // TODO: try to read sourceMappingUrl comment from the file
- var jsMap = host.readFile(jsMapPath);
- var dts = host.readFile(dtsFilename) || "/* Input file " + dtsFilename + " was missing */\r\n";
- var dtsMapPath = dtsFilename + ".map";
- var dtsMap = host.readFile(dtsMapPath);
- var node = ts.createInputFiles(js, dts, jsMap && jsMapPath, jsMap, dtsMap && dtsMapPath, dtsMap);
+ var _a = ts.getOutputPathsForBundle(resolvedRefOpts.options, /*forceDtsPaths*/ true), jsFilePath = _a.jsFilePath, sourceMapFilePath = _a.sourceMapFilePath, declarationFilePath = _a.declarationFilePath, declarationMapPath = _a.declarationMapPath;
+ var node = ts.createInputFiles(function (fileName) {
+ var path = toPath(fileName);
+ var sourceFile = getSourceFileByPath(path);
+ return sourceFile ? sourceFile.text : filesByName.has(path) ? undefined : host.readFile(path);
+ }, jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath);
nodes.push(node);
}
}
@@ -99973,6 +100069,11 @@ var ts;
}
return ts.createTextSpanFromBounds(start, end);
}
+ function getTextSpanOfEntry(entry) {
+ return entry.kind === 0 /* Span */ ? entry.textSpan :
+ getTextSpan(entry.node, entry.node.getSourceFile());
+ }
+ FindAllReferences.getTextSpanOfEntry = getTextSpanOfEntry;
/** A node is considered a writeAccess iff it is a name of a declaration or a target of an assignment */
function isWriteAccessForReference(node) {
var decl = ts.getDeclarationFromName(node);
@@ -100066,24 +100167,100 @@ var ts;
if (symbol.escapedName === "export=" /* ExportEquals */) {
return getReferencedSymbolsForModule(program, symbol.parent, /*excludeImportTypeOfExportEquals*/ false, sourceFiles, sourceFilesSet);
}
- var moduleReferences = ts.emptyArray;
- var moduleSourceFile = isModuleSymbol(symbol);
- var referencedNode = node;
- if (moduleSourceFile) {
- var exportEquals = symbol.exports.get("export=" /* ExportEquals */);
- // If !!exportEquals, we're about to add references to `import("mod")` anyway, so don't double-count them.
- moduleReferences = getReferencedSymbolsForModule(program, symbol, !!exportEquals, sourceFiles, sourceFilesSet);
- if (!exportEquals || !sourceFilesSet.has(moduleSourceFile.fileName))
- return moduleReferences;
- // Continue to get references to 'export ='.
- symbol = ts.skipAlias(exportEquals, checker);
- referencedNode = undefined;
- }
- return ts.concatenate(moduleReferences, getReferencedSymbolsForSymbol(symbol, referencedNode, sourceFiles, sourceFilesSet, checker, cancellationToken, options));
+ var moduleReferences = getReferencedSymbolsForModuleIfDeclaredBySourceFile(symbol, program, sourceFiles, cancellationToken, options, sourceFilesSet);
+ if (moduleReferences && !(symbol.flags & 33554432 /* Transient */)) {
+ return moduleReferences;
+ }
+ var aliasedSymbol = getMergedAliasedSymbolOfNamespaceExportDeclaration(node, symbol, checker);
+ var moduleReferencesOfExportTarget = aliasedSymbol &&
+ getReferencedSymbolsForModuleIfDeclaredBySourceFile(aliasedSymbol, program, sourceFiles, cancellationToken, options, sourceFilesSet);
+ var references = getReferencedSymbolsForSymbol(symbol, node, sourceFiles, sourceFilesSet, checker, cancellationToken, options);
+ return mergeReferences(program, moduleReferences, references, moduleReferencesOfExportTarget);
}
Core.getReferencedSymbolsForNode = getReferencedSymbolsForNode;
- function isModuleSymbol(symbol) {
- return symbol.flags & 1536 /* Module */ ? ts.find(symbol.declarations, ts.isSourceFile) : undefined;
+ function getMergedAliasedSymbolOfNamespaceExportDeclaration(node, symbol, checker) {
+ if (node.parent && ts.isNamespaceExportDeclaration(node.parent)) {
+ var aliasedSymbol = checker.getAliasedSymbol(symbol);
+ var targetSymbol = checker.getMergedSymbol(aliasedSymbol);
+ if (aliasedSymbol !== targetSymbol) {
+ return targetSymbol;
+ }
+ }
+ return undefined;
+ }
+ function getReferencedSymbolsForModuleIfDeclaredBySourceFile(symbol, program, sourceFiles, cancellationToken, options, sourceFilesSet) {
+ var moduleSourceFile = symbol.flags & 1536 /* Module */ ? ts.find(symbol.declarations, ts.isSourceFile) : undefined;
+ if (!moduleSourceFile)
+ return undefined;
+ var exportEquals = symbol.exports.get("export=" /* ExportEquals */);
+ // If !!exportEquals, we're about to add references to `import("mod")` anyway, so don't double-count them.
+ var moduleReferences = getReferencedSymbolsForModule(program, symbol, !!exportEquals, sourceFiles, sourceFilesSet);
+ if (!exportEquals || !sourceFilesSet.has(moduleSourceFile.fileName))
+ return moduleReferences;
+ // Continue to get references to 'export ='.
+ var checker = program.getTypeChecker();
+ symbol = ts.skipAlias(exportEquals, checker);
+ return mergeReferences(program, moduleReferences, getReferencedSymbolsForSymbol(symbol, /*node*/ undefined, sourceFiles, sourceFilesSet, checker, cancellationToken, options));
+ }
+ /**
+ * Merges the references by sorting them (by file index in sourceFiles and their location in it) that point to same definition symbol
+ */
+ function mergeReferences(program) {
+ var referencesToMerge = [];
+ for (var _i = 1; _i < arguments.length; _i++) {
+ referencesToMerge[_i - 1] = arguments[_i];
+ }
+ var result;
+ for (var _a = 0, referencesToMerge_1 = referencesToMerge; _a < referencesToMerge_1.length; _a++) {
+ var references = referencesToMerge_1[_a];
+ if (!references || !references.length)
+ continue;
+ if (!result) {
+ result = references;
+ continue;
+ }
+ var _loop_13 = function (entry) {
+ if (!entry.definition || entry.definition.type !== 0 /* Symbol */) {
+ result.push(entry);
+ return "continue";
+ }
+ var symbol = entry.definition.symbol;
+ var refIndex = ts.findIndex(result, function (ref) { return !!ref.definition &&
+ ref.definition.type === 0 /* Symbol */ &&
+ ref.definition.symbol === symbol; });
+ if (refIndex === -1) {
+ result.push(entry);
+ return "continue";
+ }
+ var reference = result[refIndex];
+ result[refIndex] = {
+ definition: reference.definition,
+ references: reference.references.concat(entry.references).sort(function (entry1, entry2) {
+ var entry1File = getSourceFileIndexOfEntry(program, entry1);
+ var entry2File = getSourceFileIndexOfEntry(program, entry2);
+ if (entry1File !== entry2File) {
+ return ts.compareValues(entry1File, entry2File);
+ }
+ var entry1Span = FindAllReferences.getTextSpanOfEntry(entry1);
+ var entry2Span = FindAllReferences.getTextSpanOfEntry(entry2);
+ return entry1Span.start !== entry2Span.start ?
+ ts.compareValues(entry1Span.start, entry2Span.start) :
+ ts.compareValues(entry1Span.length, entry2Span.length);
+ })
+ };
+ };
+ for (var _b = 0, references_1 = references; _b < references_1.length; _b++) {
+ var entry = references_1[_b];
+ _loop_13(entry);
+ }
+ }
+ return result;
+ }
+ function getSourceFileIndexOfEntry(program, entry) {
+ var sourceFile = entry.kind === 0 /* Span */ ?
+ program.getSourceFile(entry.fileName) :
+ entry.node.getSourceFile();
+ return program.getSourceFiles().indexOf(sourceFile);
}
function getReferencedSymbolsForModule(program, symbol, excludeImportTypeOfExportEquals, sourceFiles, sourceFilesSet) {
ts.Debug.assert(!!symbol.valueDeclaration);
@@ -100120,7 +100297,7 @@ var ts;
break;
default:
// This may be merged with something.
- ts.Debug.fail("Expected a module symbol to be declared by a SourceFile or ModuleDeclaration.");
+ ts.Debug.assert(!!(symbol.flags & 33554432 /* Transient */), "Expected a module symbol to be declared by a SourceFile or ModuleDeclaration.");
}
}
var exported = symbol.exports.get("export=" /* ExportEquals */);
@@ -100223,6 +100400,9 @@ var ts;
// If the symbol is declared as part of a declaration like `{ type: "a" } | { type: "b" }`, use the property on the union type to get more references.
return ts.firstDefined(symbol.declarations, function (decl) {
if (!decl.parent) {
+ // Ignore UMD module and global merge
+ if (symbol.flags & 33554432 /* Transient */)
+ return undefined;
// Assertions for GH#21814. We should be handling SourceFile symbols in `getReferencedSymbolsForModule` instead of getting here.
ts.Debug.fail("Unexpected symbol at " + ts.Debug.showSyntaxKind(node) + ": " + ts.Debug.showSymbol(symbol));
}
@@ -100237,6 +100417,12 @@ var ts;
SpecialSearchKind[SpecialSearchKind["Constructor"] = 1] = "Constructor";
SpecialSearchKind[SpecialSearchKind["Class"] = 2] = "Class";
})(SpecialSearchKind || (SpecialSearchKind = {}));
+ function getNonModuleSymbolOfMergedModuleSymbol(symbol) {
+ if (!(symbol.flags & (1536 /* Module */ | 33554432 /* Transient */)))
+ return undefined;
+ var decl = symbol.declarations && ts.find(symbol.declarations, function (d) { return !ts.isSourceFile(d) && !ts.isModuleDeclaration(d); });
+ return decl && decl.symbol;
+ }
/**
* Holds all state needed for the finding references.
* Unlike `Search`, there is only one `State`.
@@ -100295,7 +100481,7 @@ var ts;
// Note: getLocalSymbolForExportDefault handles `export default class C {}`, but not `export default C` or `export { C as default }`.
// The other two forms seem to be handled downstream (e.g. in `skipPastExportOrImportSpecifier`), so special-casing the first form
// here appears to be intentional).
- var _a = searchOptions.text, text = _a === void 0 ? ts.stripQuotes(ts.unescapeLeadingUnderscores((ts.getLocalSymbolForExportDefault(symbol) || symbol).escapedName)) : _a, _b = searchOptions.allSearchSymbols, allSearchSymbols = _b === void 0 ? [symbol] : _b;
+ var _a = searchOptions.text, text = _a === void 0 ? ts.stripQuotes(ts.unescapeLeadingUnderscores((ts.getLocalSymbolForExportDefault(symbol) || getNonModuleSymbolOfMergedModuleSymbol(symbol) || symbol).escapedName)) : _a, _b = searchOptions.allSearchSymbols, allSearchSymbols = _b === void 0 ? [symbol] : _b;
var escapedText = ts.escapeLeadingUnderscores(text);
var parents = this.options.implementations && location ? getParentSymbolsOfPropertyAccess(location, symbol, this.checker) : undefined;
return { symbol: symbol, comingFrom: comingFrom, text: text, escapedText: escapedText, parents: parents, allSearchSymbols: allSearchSymbols, includes: function (sym) { return ts.contains(allSearchSymbols, sym); } };
@@ -101131,6 +101317,13 @@ var ts;
if (res2)
return res2;
}
+ var aliasedSymbol = getMergedAliasedSymbolOfNamespaceExportDeclaration(location, symbol, checker);
+ if (aliasedSymbol) {
+ // In case of UMD module and global merging, search for global as well
+ var res_2 = cbSymbol(aliasedSymbol, /*rootSymbol*/ undefined, /*baseSymbol*/ undefined, 1 /* Node */);
+ if (res_2)
+ return res_2;
+ }
var res = fromRoot(symbol);
if (res)
return res;
@@ -101227,7 +101420,8 @@ var ts;
Core.getIntersectingMeaningFromDeclarations = getIntersectingMeaningFromDeclarations;
function isImplementation(node) {
return !!(node.flags & 4194304 /* Ambient */)
- || (ts.isVariableLike(node) ? ts.hasInitializer(node)
+ ? !(ts.isInterfaceDeclaration(node) || ts.isTypeAliasDeclaration(node))
+ : (ts.isVariableLike(node) ? ts.hasInitializer(node)
: ts.isFunctionLikeDeclaration(node) ? !!node.body
: ts.isClassLike(node) || ts.isModuleOrEnumDeclaration(node));
}
@@ -101385,7 +101579,7 @@ var ts;
}
function updateImports(program, changeTracker, oldToNew, newToOld, host, getCanonicalFileName) {
var allFiles = program.getSourceFiles();
- var _loop_13 = function (sourceFile) {
+ var _loop_14 = function (sourceFile) {
var newFromOld = oldToNew(sourceFile.path);
var newImportFromPath = newFromOld !== undefined ? newFromOld : sourceFile.path;
var newImportFromDirectory = ts.getDirectoryPath(newImportFromPath);
@@ -101417,7 +101611,7 @@ var ts;
};
for (var _i = 0, allFiles_1 = allFiles; _i < allFiles_1.length; _i++) {
var sourceFile = allFiles_1[_i];
- _loop_13(sourceFile);
+ _loop_14(sourceFile);
}
}
function combineNormal(pathA, pathB) {
@@ -102207,7 +102401,7 @@ var ts;
if (!patternMatcher)
return ts.emptyArray;
var rawItems = [];
- var _loop_14 = function (sourceFile) {
+ var _loop_15 = function (sourceFile) {
cancellationToken.throwIfCancellationRequested();
if (excludeDtsFiles && sourceFile.isDeclarationFile) {
return "continue";
@@ -102219,7 +102413,7 @@ var ts;
// Search the declarations in all files and output matched NavigateToItem into array of NavigateToItem[]
for (var _i = 0, sourceFiles_6 = sourceFiles; _i < sourceFiles_6.length; _i++) {
var sourceFile = sourceFiles_6[_i];
- _loop_14(sourceFile);
+ _loop_15(sourceFile);
}
rawItems.sort(compareNavigateToItems);
return (maxResultCount === undefined ? rawItems : rawItems.slice(0, maxResultCount)).map(createNavigateToItem);
@@ -103747,13 +103941,13 @@ var ts;
// Assumes 'value' is already lowercase.
function indexOfIgnoringCase(str, value) {
var n = str.length - value.length;
- var _loop_15 = function (start) {
+ var _loop_16 = function (start) {
if (every(value, function (valueChar, i) { return toLowerCase(str.charCodeAt(i + start)) === valueChar; })) {
return { value: start };
}
};
for (var start = 0; start <= n; start++) {
- var state_4 = _loop_15(start);
+ var state_4 = _loop_16(start);
if (typeof state_4 === "object")
return state_4.value;
}
@@ -104766,7 +104960,7 @@ var ts;
return ts.createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart);
}
function getContainingArgumentInfo(node, position, sourceFile, checker, isManuallyInvoked) {
- var _loop_16 = function (n) {
+ var _loop_17 = function (n) {
// If the node is not a subspan of its parent, this is a big problem.
// There have been crashes that might be caused by this violation.
ts.Debug.assert(ts.rangeContainsRange(n.parent, n), "Not a subspan", function () { return "Child: " + ts.Debug.showSyntaxKind(n) + ", parent: " + ts.Debug.showSyntaxKind(n.parent); });
@@ -104775,8 +104969,8 @@ var ts;
return { value: argumentInfo };
}
};
- for (var n = node; isManuallyInvoked || (!ts.isBlock(n) && !ts.isSourceFile(n)); n = n.parent) {
- var state_5 = _loop_16(n);
+ for (var n = node; !ts.isSourceFile(n) && (isManuallyInvoked || !ts.isBlock(n)); n = n.parent) {
+ var state_5 = _loop_17(n);
if (typeof state_5 === "object")
return state_5.value;
}
@@ -105933,7 +106127,7 @@ var ts;
return typeof o.type === "object" && !ts.forEachEntry(o.type, function (v) { return typeof v !== "number"; });
});
options = ts.cloneCompilerOptions(options);
- var _loop_17 = function (opt) {
+ var _loop_18 = function (opt) {
if (!ts.hasProperty(options, opt.name)) {
return "continue";
}
@@ -105952,7 +106146,7 @@ var ts;
};
for (var _i = 0, commandLineOptionsStringToEnum_1 = commandLineOptionsStringToEnum; _i < commandLineOptionsStringToEnum_1.length; _i++) {
var opt = commandLineOptionsStringToEnum_1[_i];
- _loop_17(opt);
+ _loop_18(opt);
}
return options;
}
@@ -109124,7 +109318,7 @@ var ts;
ChangeTracker.prototype.finishDeleteDeclarations = function () {
var _this = this;
var deletedNodesInLists = new ts.NodeSet(); // Stores nodes in lists that we already deleted. Used to avoid deleting `, ` twice in `a, b`.
- var _loop_18 = function (sourceFile, node) {
+ var _loop_19 = function (sourceFile, node) {
if (!this_1.deletedNodes.some(function (d) { return d.sourceFile === sourceFile && ts.rangeContainsRangeExclusive(d.node, node); })) {
if (ts.isArray(node)) {
this_1.deleteRange(sourceFile, ts.rangeOfTypeParameters(node));
@@ -109137,7 +109331,7 @@ var ts;
var this_1 = this;
for (var _i = 0, _a = this.deletedNodes; _i < _a.length; _i++) {
var _b = _a[_i], sourceFile = _b.sourceFile, node = _b.node;
- _loop_18(sourceFile, node);
+ _loop_19(sourceFile, node);
}
deletedNodesInLists.forEach(function (node) {
var sourceFile = node.getSourceFile();
@@ -109194,14 +109388,14 @@ var ts;
// order changes by start position
// If the start position is the same, put the shorter range first, since an empty range (x, x) may precede (x, y) but not vice-versa.
var normalized = ts.stableSort(changesInFile, function (a, b) { return (a.range.pos - b.range.pos) || (a.range.end - b.range.end); });
- var _loop_19 = function (i) {
+ var _loop_20 = function (i) {
ts.Debug.assert(normalized[i].range.end <= normalized[i + 1].range.pos, "Changes overlap", function () {
return JSON.stringify(normalized[i].range) + " and " + JSON.stringify(normalized[i + 1].range);
});
};
// verify that change intervals do not overlap, except possibly at end points.
for (var i = 0; i < normalized.length - 1; i++) {
- _loop_19(i);
+ _loop_20(i);
}
var textChanges = normalized.map(function (c) {
return ts.createTextChange(ts.createTextSpanFromRange(c.range), computeNewText(c, sourceFile, newLineCharacter, formatContext, validate));
@@ -110331,8 +110525,8 @@ var ts;
(function (InferFromReference) {
function inferTypesFromReferences(references, checker, cancellationToken) {
var usageContext = {};
- for (var _i = 0, references_1 = references; _i < references_1.length; _i++) {
- var reference = references_1[_i];
+ for (var _i = 0, references_2 = references; _i < references_2.length; _i++) {
+ var reference = references_2[_i];
cancellationToken.throwIfCancellationRequested();
inferTypeFromContext(reference, checker, usageContext);
}
@@ -110348,8 +110542,8 @@ var ts;
return undefined;
}
var usageContext = {};
- for (var _i = 0, references_2 = references; _i < references_2.length; _i++) {
- var reference = references_2[_i];
+ for (var _i = 0, references_3 = references; _i < references_3.length; _i++) {
+ var reference = references_3[_i];
cancellationToken.throwIfCancellationRequested();
inferTypeFromContext(reference, checker, usageContext);
}
@@ -110989,7 +111183,7 @@ var ts;
var newNodes = transformExpression(node, transformer, node);
changes.replaceNodeWithNodes(sourceFile, nodeToReplace, newNodes);
}
- var _loop_20 = function (statement) {
+ var _loop_21 = function (statement) {
ts.forEachChild(statement, function visit(node) {
if (ts.isCallExpression(node)) {
startTransformation(node, statement);
@@ -111001,7 +111195,7 @@ var ts;
};
for (var _i = 0, returnStatements_1 = returnStatements; _i < returnStatements_1.length; _i++) {
var statement = returnStatements_1[_i];
- _loop_20(statement);
+ _loop_21(statement);
}
}
function getReturnStatementsWithPromiseHandlers(body) {
@@ -112653,7 +112847,7 @@ var ts;
});
typeDeclToMembers.forEach(function (infos, classDeclaration) {
var supers = getAllSupers(classDeclaration, checker);
- var _loop_21 = function (info) {
+ var _loop_22 = function (info) {
// If some superclass added this property, don't add it again.
if (supers.some(function (superClassOrInterface) {
var superInfos = typeDeclToMembers.get(superClassOrInterface);
@@ -112680,7 +112874,7 @@ var ts;
};
for (var _i = 0, infos_1 = infos; _i < infos_1.length; _i++) {
var info = infos_1[_i];
- _loop_21(info);
+ _loop_22(info);
}
});
}));
@@ -113174,6 +113368,32 @@ var ts;
})(ts || (ts = {}));
/* @internal */
var ts;
+(function (ts) {
+ var codefix;
+ (function (codefix) {
+ var fixId = "enableExperimentalDecorators";
+ var errorCodes = [
+ ts.Diagnostics.Experimental_support_for_decorators_is_a_feature_that_is_subject_to_change_in_a_future_release_Set_the_experimentalDecorators_option_to_remove_this_warning.code
+ ];
+ codefix.registerCodeFix({
+ errorCodes: errorCodes,
+ getCodeActions: function (context) {
+ var configFile = context.program.getCompilerOptions().configFile;
+ if (configFile === undefined) {
+ return undefined;
+ }
+ var changes = ts.textChanges.ChangeTracker.with(context, function (changeTracker) { return makeChange(changeTracker, configFile); });
+ return [codefix.createCodeFixActionNoFixId(fixId, changes, ts.Diagnostics.Enable_the_experimentalDecorators_option_in_your_configuration_file)];
+ },
+ fixIds: [fixId],
+ });
+ function makeChange(changeTracker, configFile) {
+ codefix.setJsonCompilerOptionValue(changeTracker, configFile, "experimentalDecorators", ts.createTrue());
+ }
+ })(codefix = ts.codefix || (ts.codefix = {}));
+})(ts || (ts = {}));
+/* @internal */
+var ts;
(function (ts) {
var codefix;
(function (codefix) {
@@ -114928,7 +115148,7 @@ var ts;
});
var namespaceImportName = namespaceNameConflicts ? ts.getUniqueName(preferredName, sourceFile) : preferredName;
var neededNamedImports = [];
- var _loop_22 = function (element) {
+ var _loop_23 = function (element) {
var propertyName = (element.propertyName || element.name).text;
ts.FindAllReferences.Core.eachSymbolReferenceInFile(element.name, checker, sourceFile, function (id) {
var access = ts.createPropertyAccess(ts.createIdentifier(namespaceImportName), propertyName);
@@ -114947,7 +115167,7 @@ var ts;
};
for (var _i = 0, _a = toConvert.elements; _i < _a.length; _i++) {
var element = _a[_i];
- _loop_22(element);
+ _loop_23(element);
}
changes.replaceNode(sourceFile, toConvert, ts.createNamespaceImport(ts.createIdentifier(namespaceImportName)));
if (neededNamedImports.length) {
@@ -116177,7 +116397,7 @@ var ts;
: ts.getEnclosingBlockScopeContainer(scopes[0]);
ts.forEachChild(containingLexicalScopeOfExtraction, checkForUsedDeclarations);
}
- var _loop_23 = function (i) {
+ var _loop_24 = function (i) {
var scopeUsages = usagesPerScope[i];
// Special case: in the innermost scope, all usages are available.
// (The computed value reflects the value at the top-level of the scope, but the
@@ -116217,7 +116437,7 @@ var ts;
}
};
for (var i = 0; i < scopes.length; i++) {
- _loop_23(i);
+ _loop_24(i);
}
return { target: target, usagesPerScope: usagesPerScope, functionErrorsPerScope: functionErrorsPerScope, constantErrorsPerScope: constantErrorsPerScope, exposedVariableDeclarations: exposedVariableDeclarations };
function isInGenericContext(node) {
@@ -116768,10 +116988,10 @@ var ts;
}
function updateImportsInOtherFiles(changes, program, oldFile, movedSymbols, newModuleName) {
var checker = program.getTypeChecker();
- var _loop_24 = function (sourceFile) {
+ var _loop_25 = function (sourceFile) {
if (sourceFile === oldFile)
return "continue";
- var _loop_25 = function (statement) {
+ var _loop_26 = function (statement) {
forEachImportInStatement(statement, function (importNode) {
if (checker.getSymbolAtLocation(moduleSpecifierFromImport(importNode)) !== oldFile.symbol)
return;
@@ -116793,12 +117013,12 @@ var ts;
};
for (var _i = 0, _a = sourceFile.statements; _i < _a.length; _i++) {
var statement = _a[_i];
- _loop_25(statement);
+ _loop_26(statement);
}
};
for (var _i = 0, _a = program.getSourceFiles(); _i < _a.length; _i++) {
var sourceFile = _a[_i];
- _loop_24(sourceFile);
+ _loop_25(sourceFile);
}
}
function getNamespaceLikeImport(node) {
@@ -117041,6 +117261,11 @@ var ts;
var movedSymbols = new SymbolSet();
var oldImportsNeededByNewFile = new SymbolSet();
var newFileImportsFromOldFile = new SymbolSet();
+ var containsJsx = ts.find(toMove, function (statement) { return !!(statement.transformFlags & 4 /* ContainsJsx */); });
+ var jsxNamespaceSymbol = getJsxNamespaceSymbol(containsJsx);
+ if (jsxNamespaceSymbol) { // Might not exist (e.g. in non-compiling code)
+ oldImportsNeededByNewFile.add(jsxNamespaceSymbol);
+ }
for (var _i = 0, toMove_1 = toMove; _i < toMove_1.length; _i++) {
var statement = toMove_1[_i];
forEachTopLevelDeclaration(statement, function (decl) {
@@ -117069,6 +117294,10 @@ var ts;
var statement = _c[_b];
if (ts.contains(toMove, statement))
continue;
+ // jsxNamespaceSymbol will only be set iff it is in oldImportsNeededByNewFile.
+ if (jsxNamespaceSymbol && !!(statement.transformFlags & 4 /* ContainsJsx */)) {
+ unusedImportsFromOldFile.delete(jsxNamespaceSymbol);
+ }
forEachReference(statement, checker, function (symbol) {
if (movedSymbols.has(symbol))
oldFileImportsFromNewFile.add(symbol);
@@ -117076,6 +117305,19 @@ var ts;
});
}
return { movedSymbols: movedSymbols, newFileImportsFromOldFile: newFileImportsFromOldFile, oldFileImportsFromNewFile: oldFileImportsFromNewFile, oldImportsNeededByNewFile: oldImportsNeededByNewFile, unusedImportsFromOldFile: unusedImportsFromOldFile };
+ function getJsxNamespaceSymbol(containsJsx) {
+ if (containsJsx === undefined) {
+ return undefined;
+ }
+ var jsxNamespace = checker.getJsxNamespace(containsJsx);
+ // Strictly speaking, this could resolve to a symbol other than the JSX namespace.
+ // This will produce erroneous output (probably, an incorrectly copied import) but
+ // is expected to be very rare and easily reversible.
+ var jsxNamespaceSymbol = checker.resolveName(jsxNamespace, containsJsx, 1920 /* Namespace */, /*excludeGlobals*/ true);
+ return !!jsxNamespaceSymbol && ts.some(jsxNamespaceSymbol.declarations, isInImport)
+ ? jsxNamespaceSymbol
+ : undefined;
+ }
}
// Below should all be utilities
function isInImport(decl) {
@@ -117094,7 +117336,7 @@ var ts;
}
function isVariableDeclarationInImport(decl) {
return ts.isSourceFile(decl.parent.parent.parent) &&
- decl.initializer && ts.isRequireCall(decl.initializer, /*checkArgumentIsStringLiteralLike*/ true);
+ !!decl.initializer && ts.isRequireCall(decl.initializer, /*checkArgumentIsStringLiteralLike*/ true);
}
function filterImport(i, moduleSpecifier, keep) {
switch (i.kind) {
diff --git a/lib/typingsInstaller.js b/lib/typingsInstaller.js
index 8954d9a4a6d81..c4a44409f01d8 100644
--- a/lib/typingsInstaller.js
+++ b/lib/typingsInstaller.js
@@ -88,7 +88,7 @@ var ts;
// If changing the text in this section, be sure to test `configureNightly` too.
ts.versionMajorMinor = "3.3";
/** The version of the TypeScript compiler release */
- ts.version = ts.versionMajorMinor + ".0-rc";
+ ts.version = ts.versionMajorMinor + ".1";
})(ts || (ts = {}));
(function (ts) {
/* @internal */
@@ -5533,7 +5533,6 @@ var ts;
Property_0_is_used_before_being_assigned: diag(2565, ts.DiagnosticCategory.Error, "Property_0_is_used_before_being_assigned_2565", "Property '{0}' is used before being assigned."),
A_rest_element_cannot_have_a_property_name: diag(2566, ts.DiagnosticCategory.Error, "A_rest_element_cannot_have_a_property_name_2566", "A rest element cannot have a property name."),
Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations: diag(2567, ts.DiagnosticCategory.Error, "Enum_declarations_can_only_merge_with_namespace_or_other_enum_declarations_2567", "Enum declarations can only merge with namespace or other enum declarations."),
- Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators: diag(2568, ts.DiagnosticCategory.Error, "Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators_2568", "Type '{0}' is not an array type. Use compiler option '--downlevelIteration' to allow iterating of iterators."),
Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators: diag(2569, ts.DiagnosticCategory.Error, "Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterati_2569", "Type '{0}' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators."),
Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await: diag(2570, ts.DiagnosticCategory.Error, "Property_0_does_not_exist_on_type_1_Did_you_forget_to_use_await_2570", "Property '{0}' does not exist on type '{1}'. Did you forget to use 'await'?"),
Object_is_of_type_unknown: diag(2571, ts.DiagnosticCategory.Error, "Object_is_of_type_unknown_2571", "Object is of type 'unknown'."),
@@ -5628,7 +5627,7 @@ var ts;
Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor: diag(2715, ts.DiagnosticCategory.Error, "Abstract_property_0_in_class_1_cannot_be_accessed_in_the_constructor_2715", "Abstract property '{0}' in class '{1}' cannot be accessed in the constructor."),
Type_parameter_0_has_a_circular_default: diag(2716, ts.DiagnosticCategory.Error, "Type_parameter_0_has_a_circular_default_2716", "Type parameter '{0}' has a circular default."),
Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_type_2: diag(2717, ts.DiagnosticCategory.Error, "Subsequent_property_declarations_must_have_the_same_type_Property_0_must_be_of_type_1_but_here_has_t_2717", "Subsequent property declarations must have the same type. Property '{0}' must be of type '{1}', but here has type '{2}'."),
- Duplicate_declaration_0: diag(2718, ts.DiagnosticCategory.Error, "Duplicate_declaration_0_2718", "Duplicate declaration '{0}'."),
+ Duplicate_property_0: diag(2718, ts.DiagnosticCategory.Error, "Duplicate_property_0_2718", "Duplicate property '{0}'."),
Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated: diag(2719, ts.DiagnosticCategory.Error, "Type_0_is_not_assignable_to_type_1_Two_different_types_with_this_name_exist_but_they_are_unrelated_2719", "Type '{0}' is not assignable to type '{1}'. Two different types with this name exist, but they are unrelated."),
Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclass: diag(2720, ts.DiagnosticCategory.Error, "Class_0_incorrectly_implements_class_1_Did_you_mean_to_extend_1_and_inherit_its_members_as_a_subclas_2720", "Class '{0}' incorrectly implements class '{1}'. Did you mean to extend '{1}' and inherit its members as a subclass?"),
Cannot_invoke_an_object_which_is_possibly_null: diag(2721, ts.DiagnosticCategory.Error, "Cannot_invoke_an_object_which_is_possibly_null_2721", "Cannot invoke an object which is possibly 'null'."),
@@ -5643,6 +5642,7 @@ var ts;
An_arrow_function_cannot_have_a_this_parameter: diag(2730, ts.DiagnosticCategory.Error, "An_arrow_function_cannot_have_a_this_parameter_2730", "An arrow function cannot have a 'this' parameter."),
Implicit_conversion_of_a_symbol_to_a_string_will_fail_at_runtime_Consider_wrapping_this_expression_in_String: diag(2731, ts.DiagnosticCategory.Error, "Implicit_conversion_of_a_symbol_to_a_string_will_fail_at_runtime_Consider_wrapping_this_expression_i_2731", "Implicit conversion of a 'symbol' to a 'string' will fail at runtime. Consider wrapping this expression in 'String(...)'."),
Cannot_find_module_0_Consider_using_resolveJsonModule_to_import_module_with_json_extension: diag(2732, ts.DiagnosticCategory.Error, "Cannot_find_module_0_Consider_using_resolveJsonModule_to_import_module_with_json_extension_2732", "Cannot find module '{0}'. Consider using '--resolveJsonModule' to import module with '.json' extension"),
+ Property_0_was_also_declared_here: diag(2733, ts.DiagnosticCategory.Error, "Property_0_was_also_declared_here_2733", "Property '{0}' was also declared here."),
It_is_highly_likely_that_you_are_missing_a_semicolon: diag(2734, ts.DiagnosticCategory.Error, "It_is_highly_likely_that_you_are_missing_a_semicolon_2734", "It is highly likely that you are missing a semicolon."),
Did_you_mean_for_0_to_be_constrained_to_type_new_args_Colon_any_1: diag(2735, ts.DiagnosticCategory.Error, "Did_you_mean_for_0_to_be_constrained_to_type_new_args_Colon_any_1_2735", "Did you mean for '{0}' to be constrained to type 'new (...args: any[]) => {1}'?"),
Operator_0_cannot_be_applied_to_type_1: diag(2736, ts.DiagnosticCategory.Error, "Operator_0_cannot_be_applied_to_type_1_2736", "Operator '{0}' cannot be applied to type '{1}'."),
@@ -6930,6 +6930,7 @@ var ts;
scanJsxIdentifier: scanJsxIdentifier,
scanJsxAttributeValue: scanJsxAttributeValue,
reScanJsxToken: reScanJsxToken,
+ reScanLessThanToken: reScanLessThanToken,
scanJsxToken: scanJsxToken,
scanJSDocToken: scanJSDocToken,
scan: scan,
@@ -7926,6 +7927,13 @@ var ts;
pos = tokenPos = startPos;
return token = scanJsxToken();
}
+ function reScanLessThanToken() {
+ if (token === 46 /* LessThanLessThanToken */) {
+ pos = tokenPos + 1;
+ return token = 28 /* LessThanToken */;
+ }
+ return token;
+ }
function scanJsxToken() {
startPos = tokenPos = pos;
if (pos >= end) {
@@ -8862,7 +8870,9 @@ var ts;
case 14 /* NoSubstitutionTemplateLiteral */:
return ts.escapeLeadingUnderscores(name.text);
case 149 /* ComputedPropertyName */:
- return isStringOrNumericLiteralLike(name.expression) ? ts.escapeLeadingUnderscores(name.expression.text) : undefined; // TODO: GH#18217 Almost all uses of this assume the result to be defined!
+ if (isStringOrNumericLiteralLike(name.expression))
+ return ts.escapeLeadingUnderscores(name.expression.text);
+ return ts.Debug.fail("Text of property name cannot be read from non-literal-valued ComputedPropertyNames");
default:
return ts.Debug.assertNever(name);
}
@@ -17208,6 +17218,9 @@ var ts;
function reScanTemplateToken() {
return currentToken = scanner.reScanTemplateToken();
}
+ function reScanLessThanToken() {
+ return currentToken = scanner.reScanLessThanToken();
+ }
function scanJsxIdentifier() {
return currentToken = scanner.scanJsxIdentifier();
}
@@ -18219,7 +18232,7 @@ var ts;
function parseTypeReference() {
var node = createNode(164 /* TypeReference */);
node.typeName = parseEntityName(/*allowReservedWords*/ true, ts.Diagnostics.Type_expected);
- if (!scanner.hasPrecedingLineBreak() && token() === 28 /* LessThanToken */) {
+ if (!scanner.hasPrecedingLineBreak() && reScanLessThanToken() === 28 /* LessThanToken */) {
node.typeArguments = parseBracketedList(20 /* TypeArguments */, parseType, 28 /* LessThanToken */, 30 /* GreaterThanToken */);
}
return finishNode(node);
@@ -20241,7 +20254,8 @@ var ts;
function parseCallExpressionRest(expression) {
while (true) {
expression = parseMemberExpressionRest(expression);
- if (token() === 28 /* LessThanToken */) {
+ // handle 'foo<()'
+ if (token() === 28 /* LessThanToken */ || token() === 46 /* LessThanLessThanToken */) {
// See if this is the start of a generic invocation. If so, consume it and
// keep checking for postfix expressions. Otherwise, it's just a '<' that's
// part of an arithmetic expression. Break out so we consume it higher in the
@@ -20278,9 +20292,10 @@ var ts;
return result;
}
function parseTypeArgumentsInExpression() {
- if (!parseOptional(28 /* LessThanToken */)) {
+ if (reScanLessThanToken() !== 28 /* LessThanToken */) {
return undefined;
}
+ nextToken();
var typeArguments = parseDelimitedList(20 /* TypeArguments */, parseType);
if (!parseExpected(30 /* GreaterThanToken */)) {
// If it doesn't have the closing `>` then it's definitely not an type argument list.
@@ -27153,6 +27168,7 @@ var ts;
ContainerFlags[ContainerFlags["IsInterface"] = 64] = "IsInterface";
ContainerFlags[ContainerFlags["IsObjectLiteralOrClassExpressionMethod"] = 128] = "IsObjectLiteralOrClassExpressionMethod";
})(ContainerFlags || (ContainerFlags = {}));
+ var flowNodeCreated = ts.identity;
var binder = createBinder();
function bindSourceFile(file, options) {
ts.performance.mark("beforeBind");
@@ -27541,6 +27557,7 @@ var ts;
blockScopeContainer.locals = undefined;
}
if (containerFlags & 4 /* IsControlFlowContainer */) {
+ var saveFlowNodeCreated = flowNodeCreated;
var saveCurrentFlow = currentFlow;
var saveBreakTarget = currentBreakTarget;
var saveContinueTarget = currentContinueTarget;
@@ -27564,6 +27581,7 @@ var ts;
currentContinueTarget = undefined;
activeLabels = undefined;
hasExplicitReturn = false;
+ flowNodeCreated = ts.identity;
bindChildren(node);
// Reset all reachability check related flags on node (for incremental scenarios)
node.flags &= ~1408 /* ReachabilityAndEmitFlags */;
@@ -27590,6 +27608,7 @@ var ts;
currentReturnTarget = saveReturnTarget;
activeLabels = saveActiveLabels;
hasExplicitReturn = saveHasExplicitReturn;
+ flowNodeCreated = saveFlowNodeCreated;
}
else if (containerFlags & 64 /* IsInterface */) {
seenThisKeyword = false;
@@ -27853,22 +27872,22 @@ var ts;
return antecedent;
}
setFlowNodeReferenced(antecedent);
- return { flags: flags, expression: expression, antecedent: antecedent };
+ return flowNodeCreated({ flags: flags, expression: expression, antecedent: antecedent });
}
function createFlowSwitchClause(antecedent, switchStatement, clauseStart, clauseEnd) {
if (!isNarrowingExpression(switchStatement.expression)) {
return antecedent;
}
setFlowNodeReferenced(antecedent);
- return { flags: 128 /* SwitchClause */, switchStatement: switchStatement, clauseStart: clauseStart, clauseEnd: clauseEnd, antecedent: antecedent };
+ return flowNodeCreated({ flags: 128 /* SwitchClause */, switchStatement: switchStatement, clauseStart: clauseStart, clauseEnd: clauseEnd, antecedent: antecedent });
}
function createFlowAssignment(antecedent, node) {
setFlowNodeReferenced(antecedent);
- return { flags: 16 /* Assignment */, antecedent: antecedent, node: node };
+ return flowNodeCreated({ flags: 16 /* Assignment */, antecedent: antecedent, node: node });
}
function createFlowArrayMutation(antecedent, node) {
setFlowNodeReferenced(antecedent);
- var res = { flags: 256 /* ArrayMutation */, antecedent: antecedent, node: node };
+ var res = flowNodeCreated({ flags: 256 /* ArrayMutation */, antecedent: antecedent, node: node });
return res;
}
function finishFlowLabel(flow) {
@@ -28056,18 +28075,46 @@ var ts;
function bindTryStatement(node) {
var preFinallyLabel = createBranchLabel();
var preTryFlow = currentFlow;
- // TODO: Every statement in try block is potentially an exit point!
+ var tryPriors = [];
+ var oldFlowNodeCreated = flowNodeCreated;
+ // We hook the creation of all flow nodes within the `try` scope and store them so we can add _all_ of them
+ // as possible antecedents of the start of the `catch` or `finally` blocks.
+ // Don't bother intercepting the call if there's no finally or catch block that needs the information
+ if (node.catchClause || node.finallyBlock) {
+ flowNodeCreated = function (node) { return (tryPriors.push(node), node); };
+ }
bind(node.tryBlock);
+ flowNodeCreated = oldFlowNodeCreated;
addAntecedent(preFinallyLabel, currentFlow);
var flowAfterTry = currentFlow;
var flowAfterCatch = unreachableFlow;
if (node.catchClause) {
currentFlow = preTryFlow;
+ if (tryPriors.length) {
+ var preCatchFlow = createBranchLabel();
+ addAntecedent(preCatchFlow, currentFlow);
+ for (var _i = 0, tryPriors_1 = tryPriors; _i < tryPriors_1.length; _i++) {
+ var p = tryPriors_1[_i];
+ addAntecedent(preCatchFlow, p);
+ }
+ currentFlow = finishFlowLabel(preCatchFlow);
+ }
bind(node.catchClause);
addAntecedent(preFinallyLabel, currentFlow);
flowAfterCatch = currentFlow;
}
if (node.finallyBlock) {
+ // We add the nodes within the `try` block to the `finally`'s antecedents if there's no catch block
+ // (If there is a `catch` block, it will have all these antecedents instead, and the `finally` will
+ // have the end of the `try` block and the end of the `catch` block)
+ if (!node.catchClause) {
+ if (tryPriors.length) {
+ for (var _a = 0, tryPriors_2 = tryPriors; _a < tryPriors_2.length; _a++) {
+ var p = tryPriors_2[_a];
+ addAntecedent(preFinallyLabel, p);
+ }
+ }
+ }
// in finally flow is combined from pre-try/flow from try/flow from catch
// pre-flow is necessary to make sure that finally is reachable even if finally flows in both try and finally blocks are unreachable
// also for finally blocks we inject two extra edges into the flow graph.
@@ -28112,7 +28159,7 @@ var ts;
}
}
if (!(currentFlow.flags & 1 /* Unreachable */)) {
- var afterFinallyFlow = { flags: 4096 /* AfterFinally */, antecedent: currentFlow };
+ var afterFinallyFlow = flowNodeCreated({ flags: 4096 /* AfterFinally */, antecedent: currentFlow });
preFinallyFlow.lock = afterFinallyFlow;
currentFlow = afterFinallyFlow;
}
@@ -35638,16 +35685,17 @@ var ts;
var objectFlags = 128 /* ObjectLiteral */;
ts.forEach(pattern.elements, function (e) {
var name = e.propertyName || e.name;
- if (isComputedNonLiteralName(name)) {
- // do not include computed properties in the implied type
- objectFlags |= 512 /* ObjectLiteralPatternWithComputedProperties */;
- return;
- }
if (e.dotDotDotToken) {
stringIndexInfo = createIndexInfo(anyType, /*isReadonly*/ false);
return;
}
- var text = ts.getTextOfPropertyName(name);
+ var exprType = getLiteralTypeFromPropertyName(name);
+ if (!isTypeUsableAsPropertyName(exprType)) {
+ // do not include computed properties in the implied type
+ objectFlags |= 512 /* ObjectLiteralPatternWithComputedProperties */;
+ return;
+ }
+ var text = getPropertyNameFromType(exprType);
var flags = 4 /* Property */ | (e.initializer ? 16777216 /* Optional */ : 0);
var symbol = createSymbol(flags, text);
symbol.type = getTypeFromBindingElement(e, includePatternInType, reportErrors);
@@ -36689,9 +36737,9 @@ var ts;
return type;
}
/**
- * Indicates whether a type can be used as a late-bound name.
+ * Indicates whether a type can be used as a property name.
*/
- function isTypeUsableAsLateBoundName(type) {
+ function isTypeUsableAsPropertyName(type) {
return !!(type.flags & 8576 /* StringOrNumberLiteralOrUnique */);
}
/**
@@ -36705,7 +36753,7 @@ var ts;
function isLateBindableName(node) {
return ts.isComputedPropertyName(node)
&& ts.isEntityNameExpression(node.expression)
- && isTypeUsableAsLateBoundName(checkComputedPropertyName(node));
+ && isTypeUsableAsPropertyName(checkComputedPropertyName(node));
}
function isLateBoundName(name) {
return name.charCodeAt(0) === 95 /* _ */ &&
@@ -36732,11 +36780,11 @@ var ts;
return ts.isDynamicName(node) && !isLateBindableName(node);
}
/**
- * Gets the symbolic name for a late-bound member from its type.
+ * Gets the symbolic name for a member from its type.
*/
- function getLateBoundNameFromType(type) {
+ function getPropertyNameFromType(type) {
if (type.flags & 8192 /* UniqueESSymbol */) {
- return "__@" + type.symbol.escapedName + "@" + getSymbolId(type.symbol);
+ return type.escapedName;
}
if (type.flags & (128 /* StringLiteral */ | 256 /* NumberLiteral */)) {
return ts.escapeLeadingUnderscores("" + type.value);
@@ -36800,8 +36848,8 @@ var ts;
// fall back to the early-bound name of this member.
links.resolvedSymbol = decl.symbol;
var type = checkComputedPropertyName(decl.name);
- if (isTypeUsableAsLateBoundName(type)) {
- var memberName = getLateBoundNameFromType(type);
+ if (isTypeUsableAsPropertyName(type)) {
+ var memberName = getPropertyNameFromType(type);
var symbolFlags = decl.symbol.flags;
// Get or add a late-bound symbol for the member. This allows us to merge late-bound accessor declarations.
var lateSymbol = lateSymbols.get(memberName);
@@ -36815,9 +36863,9 @@ var ts;
// If we have an existing early-bound member, combine its declarations so that we can
// report an error at each declaration.
var declarations = earlySymbol ? ts.concatenate(earlySymbol.declarations, lateSymbol.declarations) : lateSymbol.declarations;
- var name_3 = ts.declarationNameToString(decl.name);
- ts.forEach(declarations, function (declaration) { return error(ts.getNameOfDeclaration(declaration) || declaration, ts.Diagnostics.Duplicate_declaration_0, name_3); });
- error(decl.name || decl, ts.Diagnostics.Duplicate_declaration_0, name_3);
+ var name_3 = !(type.flags & 8192 /* UniqueESSymbol */) && ts.unescapeLeadingUnderscores(memberName) || ts.declarationNameToString(decl.name);
+ ts.forEach(declarations, function (declaration) { return error(ts.getNameOfDeclaration(declaration) || declaration, ts.Diagnostics.Property_0_was_also_declared_here, name_3); });
+ error(decl.name || decl, ts.Diagnostics.Duplicate_property_0, name_3);
lateSymbol = createSymbol(0 /* None */, memberName, 2048 /* Late */);
}
lateSymbol.nameType = type;
@@ -37409,8 +37457,8 @@ var ts;
var propType = instantiateType(templateType, templateMapper);
// If the current iteration type constituent is a string literal type, create a property.
// Otherwise, for type string create a string index signature.
- if (t.flags & 8576 /* StringOrNumberLiteralOrUnique */) {
- var propName = getLateBoundNameFromType(t);
+ if (isTypeUsableAsPropertyName(t)) {
+ var propName = getPropertyNameFromType(t);
var modifiersProp = getPropertyOfType(modifiersType, propName);
var isOptional = !!(templateModifiers & 4 /* IncludeOptional */ ||
!(templateModifiers & 8 /* ExcludeOptional */) && modifiersProp && modifiersProp.flags & 16777216 /* Optional */);
@@ -37580,7 +37628,8 @@ var ts;
function isTypeInvalidDueToUnionDiscriminant(contextualType, obj) {
var list = obj.properties;
return list.some(function (property) {
- var name = property.name && ts.getTextOfPropertyName(property.name);
+ var nameType = property.name && getLiteralTypeFromPropertyName(property.name);
+ var name = nameType && isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined;
var expected = name === undefined ? undefined : getTypeOfPropertyOfType(contextualType, name);
return !!expected && isLiteralType(expected) && !isTypeIdenticalTo(getTypeOfNode(property), expected);
});
@@ -37950,6 +37999,10 @@ var ts;
result.containingType = containingType;
if (!hasNonUniformValueDeclaration && firstValueDeclaration) {
result.valueDeclaration = firstValueDeclaration;
+ // Inherit information about parent type.
+ if (firstValueDeclaration.symbol.parent) {
+ result.parent = firstValueDeclaration.symbol.parent;
+ }
}
result.declarations = declarations;
result.nameType = nameType;
@@ -38808,21 +38861,16 @@ var ts;
* the type of this reference is just the type of the value we resolved to.
*/
function getJSDocTypeReference(node, symbol, typeArguments) {
- if (!pushTypeResolution(symbol, 6 /* JSDocTypeReference */)) {
- return errorType;
- }
- var assignedType = getAssignedClassType(symbol);
- var valueType = getTypeOfSymbol(symbol);
- var referenceType = valueType.symbol && valueType.symbol !== symbol && !isInferredClassType(valueType) && getTypeReferenceTypeWorker(node, valueType.symbol, typeArguments);
- if (!popTypeResolution()) {
- getSymbolLinks(symbol).resolvedJSDocType = errorType;
- error(node, ts.Diagnostics.JSDoc_type_0_circularly_references_itself, symbolToString(symbol));
- return errorType;
- }
- if (referenceType || assignedType) {
- // TODO: GH#18217 (should the `|| assignedType` be at a lower precedence?)
- var type = (referenceType && assignedType ? getIntersectionType([assignedType, referenceType]) : referenceType || assignedType);
- return getSymbolLinks(symbol).resolvedJSDocType = type;
+ // In the case of an assignment of a function expression (binary expressions, variable declarations, etc.), we will get the
+ // correct instance type for the symbol on the LHS by finding the type for RHS. For example if we want to get the type of the symbol `foo`:
+ // var foo = function() {}
+ // We will find the static type of the assigned anonymous function.
+ var staticType = getTypeOfSymbol(symbol);
+ var instanceType = staticType.symbol &&
+ staticType.symbol !== symbol && // Make sure this is an assignment like expression by checking that symbol -> type -> symbol doesn't roundtrips.
+ getTypeReferenceTypeWorker(node, staticType.symbol, typeArguments); // Get the instance type of the RHS symbol.
+ if (instanceType) {
+ return getSymbolLinks(symbol).resolvedJSDocType = instanceType;
}
}
function getTypeReferenceTypeWorker(node, symbol, typeArguments) {
@@ -38840,8 +38888,11 @@ var ts;
}
if (symbol.flags & 16 /* Function */ &&
isJSDocTypeReference(node) &&
- (symbol.members || ts.getJSDocClassTag(symbol.valueDeclaration))) {
- return getInferredClassType(symbol);
+ isJSConstructor(symbol.valueDeclaration)) {
+ var resolved = resolveStructuredTypeMembers(getTypeOfSymbol(symbol));
+ if (resolved.callSignatures.length === 1) {
+ return getReturnTypeOfSignature(resolved.callSignatures[0]);
+ }
}
}
function getSubstitutionType(typeVariable, substitute) {
@@ -39738,8 +39789,8 @@ var ts;
}
function getPropertyTypeForIndexType(objectType, indexType, accessNode, cacheSymbol, missingType) {
var accessExpression = accessNode && accessNode.kind === 190 /* ElementAccessExpression */ ? accessNode : undefined;
- var propName = isTypeUsableAsLateBoundName(indexType) ?
- getLateBoundNameFromType(indexType) :
+ var propName = isTypeUsableAsPropertyName(indexType) ?
+ getPropertyNameFromType(indexType) :
accessExpression && checkThatExpressionIsProperSymbolReference(accessExpression.argumentExpression, indexType, /*reportError*/ false) ?
ts.getPropertyNameForKnownSymbolName(ts.idText(accessExpression.argumentExpression.name)) :
accessNode && ts.isPropertyName(accessNode) ?
@@ -40383,6 +40434,7 @@ var ts;
function createUniqueESSymbolType(symbol) {
var type = createType(8192 /* UniqueESSymbol */);
type.symbol = symbol;
+ type.escapedName = "__@" + type.symbol.escapedName + "@" + getSymbolId(type.symbol);
return type;
}
function getESSymbolLikeTypeForNode(node) {
@@ -40580,7 +40632,9 @@ var ts;
return type.flags & 262144 /* TypeParameter */ ? wildcardType : type;
}
function getRestrictiveTypeParameter(tp) {
- return !tp.constraint ? tp : tp.restrictiveInstantiation || (tp.restrictiveInstantiation = createTypeParameter(tp.symbol));
+ return tp.constraint === unknownType ? tp : tp.restrictiveInstantiation || (tp.restrictiveInstantiation = createTypeParameter(tp.symbol),
+ tp.restrictiveInstantiation.constraint = unknownType,
+ tp.restrictiveInstantiation);
}
function restrictiveMapper(type) {
return type.flags & 262144 /* TypeParameter */ ? getRestrictiveTypeParameter(type) : type;
@@ -41195,7 +41249,7 @@ var ts;
}
if (resultObj.error) {
var reportedDiag = resultObj.error;
- var propertyName = isTypeUsableAsLateBoundName(nameType) ? getLateBoundNameFromType(nameType) : undefined;
+ var propertyName = isTypeUsableAsPropertyName(nameType) ? getPropertyNameFromType(nameType) : undefined;
var targetProp = propertyName !== undefined ? getPropertyOfType(target, propertyName) : undefined;
var issuedElaboration = false;
if (!targetProp) {
@@ -42551,7 +42605,7 @@ var ts;
}
else {
// An empty object type is related to any mapped type that includes a '?' modifier.
- if (isPartialMappedType(target) && isEmptyObjectType(source)) {
+ if (relation !== subtypeRelation && isPartialMappedType(target) && isEmptyObjectType(source)) {
return -1 /* True */;
}
if (isGenericMappedType(target)) {
@@ -44355,7 +44409,11 @@ var ts;
priority |= 4 /* MappedTypeConstraint */;
inferFromTypes(getIndexType(source), constraintType);
priority = savePriority;
- inferFromTypes(getUnionType(ts.map(getPropertiesOfType(source), getTypeOfSymbol)), getTemplateTypeFromMappedType(target));
+ var valueTypes = ts.compact([
+ getIndexTypeOfType(source, 0 /* String */),
+ getIndexTypeOfType(source, 1 /* Number */)
+ ].concat(ts.map(getPropertiesOfType(source), getTypeOfSymbol)));
+ inferFromTypes(getUnionType(valueTypes), getTemplateTypeFromMappedType(target));
return true;
}
return false;
@@ -44912,7 +44970,10 @@ var ts;
return type;
}
function getTypeOfDestructuredProperty(type, name) {
- var text = ts.getTextOfPropertyName(name);
+ var nameType = getLiteralTypeFromPropertyName(name);
+ if (!isTypeUsableAsPropertyName(nameType))
+ return errorType;
+ var text = getPropertyNameFromType(nameType);
return getConstraintForLocation(getTypeOfPropertyOfType(type, text), name) ||
isNumericLiteralName(text) && getIndexTypeOfType(type, 1 /* Number */) ||
getIndexTypeOfType(type, 0 /* String */) ||
@@ -45470,9 +45531,6 @@ var ts;
}
function getTypeAtSwitchClause(flow) {
var expr = flow.switchStatement.expression;
- if (containsMatchingReferenceDiscriminant(reference, expr)) {
- return declaredType;
- }
var flowType = getTypeAtFlowNode(flow.antecedent);
var type = getTypeFromFlowType(flowType);
if (isMatchingReference(reference, expr)) {
@@ -45484,6 +45542,9 @@ var ts;
else if (expr.kind === 199 /* TypeOfExpression */ && isMatchingReference(reference, expr.expression)) {
type = narrowBySwitchOnTypeOf(type, flow.switchStatement, flow.clauseStart, flow.clauseEnd);
}
+ else if (containsMatchingReferenceDiscriminant(reference, expr)) {
+ type = declaredType;
+ }
return createFlowType(type, isIncomplete(flowType));
}
function getTypeAtFlowBranchLabel(flow) {
@@ -46476,7 +46537,7 @@ var ts;
else if (isInJS &&
(container.kind === 196 /* FunctionExpression */ || container.kind === 239 /* FunctionDeclaration */) &&
ts.getJSDocClassTag(container)) {
- var classType = getJSClassType(container.symbol);
+ var classType = getJSClassType(getMergedSymbol(container.symbol));
if (classType) {
return getFlowTypeOfReference(node, classType);
}
@@ -46871,9 +46932,10 @@ var ts;
var parentDeclaration = declaration.parent.parent;
var name = declaration.propertyName || declaration.name;
var parentType = getContextualTypeForVariableLikeDeclaration(parentDeclaration);
- if (parentType && !ts.isBindingPattern(name)) {
- var text = ts.getTextOfPropertyName(name);
- if (text !== undefined) {
+ if (parentType && !ts.isBindingPattern(name) && !isComputedNonLiteralName(name)) {
+ var nameType = getLiteralTypeFromPropertyName(name);
+ if (isTypeUsableAsPropertyName(nameType)) {
+ var text = getPropertyNameFromType(nameType);
return getTypeOfPropertyOfType(parentType, text);
}
}
@@ -47747,10 +47809,9 @@ var ts;
}
}
typeFlags |= type.flags;
- var nameType = computedNameType && computedNameType.flags & 8576 /* StringOrNumberLiteralOrUnique */ ?
- computedNameType : undefined;
+ var nameType = computedNameType && isTypeUsableAsPropertyName(computedNameType) ? computedNameType : undefined;
var prop = nameType ?
- createSymbol(4 /* Property */ | member.flags, getLateBoundNameFromType(nameType), 2048 /* Late */) :
+ createSymbol(4 /* Property */ | member.flags, getPropertyNameFromType(nameType), 2048 /* Late */) :
createSymbol(4 /* Property */ | member.flags, member.escapedName);
if (nameType) {
prop.nameType = nameType;
@@ -48008,6 +48069,10 @@ var ts;
childrenPropSymbol.type = childrenTypes.length === 1 ?
childrenTypes[0] :
(getArrayLiteralTupleTypeIfApplicable(childrenTypes, childrenContextualType, /*hasRestElement*/ false) || createArrayType(getUnionType(childrenTypes)));
+ // Fake up a property declaration for the children
+ childrenPropSymbol.valueDeclaration = ts.createPropertySignature(/*modifiers*/ undefined, ts.unescapeLeadingUnderscores(jsxChildrenPropertyName), /*questionToken*/ undefined, /*type*/ undefined, /*initializer*/ undefined);
+ childrenPropSymbol.valueDeclaration.parent = attributes;
+ childrenPropSymbol.valueDeclaration.symbol = childrenPropSymbol;
var childPropMap = ts.createSymbolTable();
childPropMap.set(jsxChildrenPropertyName, childrenPropSymbol);
spread = getSpreadType(spread, createAnonymousType(attributes.symbol, childPropMap, ts.emptyArray, ts.emptyArray, /*stringIndexInfo*/ undefined, /*numberIndexInfo*/ undefined), attributes.symbol, typeFlags, objectFlags);
@@ -49687,6 +49752,12 @@ var ts;
if (inferenceContext) {
var typeArgumentTypes = inferTypeArguments(node, candidate, args, excludeArgument, inferenceContext);
checkCandidate = getSignatureInstantiation(candidate, typeArgumentTypes, ts.isInJSFile(candidate.declaration));
+ // If the original signature has a generic rest type, instantiation may produce a
+ // signature with different arity and we need to perform another arity check.
+ if (getNonArrayRestType(candidate) && !hasCorrectArity(node, args, checkCandidate, signatureHelpTrailingComma)) {
+ candidateForArgumentArityError = checkCandidate;
+ continue;
+ }
}
if (!checkApplicableSignature(node, args, checkCandidate, relation, excludeArgument, /*reportErrors*/ false)) {
// Give preference to error candidates that have no rest parameters (as they are more specific)
@@ -50238,7 +50309,7 @@ var ts;
return true;
// If the symbol of the node has members, treat it like a constructor.
var symbol = getSymbolOfNode(func);
- return !!symbol && symbol.members !== undefined;
+ return !!symbol && (symbol.members !== undefined || symbol.exports !== undefined && symbol.exports.get("prototype") !== undefined);
}
return false;
}
@@ -50255,10 +50326,6 @@ var ts;
inferred = getInferredClassType(symbol);
}
var assigned = getAssignedClassType(symbol);
- var valueType = getTypeOfSymbol(symbol);
- if (valueType.symbol && !isInferredClassType(valueType) && isJSConstructor(valueType.symbol.valueDeclaration)) {
- inferred = getInferredClassType(valueType.symbol);
- }
return assigned && inferred ?
getIntersectionType([inferred, assigned]) :
assigned || inferred;
@@ -50293,11 +50360,6 @@ var ts;
}
return links.inferredClassType;
}
- function isInferredClassType(type) {
- return type.symbol
- && ts.getObjectFlags(type) & 16 /* Anonymous */
- && getSymbolLinks(type.symbol).inferredClassType === type;
- }
/**
* Syntactically and semantically checks a call or new expression.
* @param node The call/new expression to be checked.
@@ -50316,20 +50378,9 @@ var ts;
declaration.kind !== 157 /* Constructor */ &&
declaration.kind !== 161 /* ConstructSignature */ &&
declaration.kind !== 166 /* ConstructorType */ &&
- !ts.isJSDocConstructSignature(declaration)) {
- // When resolved signature is a call signature (and not a construct signature) the result type is any, unless
- // the declaring function had members created through 'x.prototype.y = expr' or 'this.y = expr' psuedodeclarations
- // in a JS file
- // Note:JS inferred classes might come from a variable declaration instead of a function declaration.
- // In this case, using getResolvedSymbol directly is required to avoid losing the members from the declaration.
- var funcSymbol = checkExpression(node.expression).symbol;
- if (!funcSymbol && node.expression.kind === 72 /* Identifier */) {
- funcSymbol = getResolvedSymbol(node.expression);
- }
- var type = funcSymbol && getJSClassType(funcSymbol);
- if (type) {
- return signature.target ? instantiateType(type, signature.mapper) : type;
- }
+ !ts.isJSDocConstructSignature(declaration) &&
+ !isJSConstructor(declaration)) {
+ // When resolved signature is a call signature (and not a construct signature) the result type is any
if (noImplicitAny) {
error(node, ts.Diagnostics.new_expression_whose_target_lacks_a_construct_signature_implicitly_has_an_any_type);
}
@@ -51384,7 +51435,7 @@ var ts;
if (!(isTypeComparableTo(leftType, stringType) || isTypeAssignableToKind(leftType, 296 /* NumberLike */ | 12288 /* ESSymbolLike */))) {
error(left, ts.Diagnostics.The_left_hand_side_of_an_in_expression_must_be_of_type_any_string_number_or_symbol);
}
- if (!isTypeAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */)) {
+ if (!allTypesAssignableToKind(rightType, 67108864 /* NonPrimitive */ | 58982400 /* InstantiableNonPrimitive */)) {
error(right, ts.Diagnostics.The_right_hand_side_of_an_in_expression_must_be_of_type_any_an_object_type_or_a_type_parameter);
}
return booleanType;
@@ -51405,15 +51456,15 @@ var ts;
if (rightIsThis === void 0) { rightIsThis = false; }
if (property.kind === 275 /* PropertyAssignment */ || property.kind === 276 /* ShorthandPropertyAssignment */) {
var name = property.name;
- var text = ts.getTextOfPropertyName(name);
- if (text) {
+ var exprType = getLiteralTypeFromPropertyName(name);
+ if (isTypeUsableAsPropertyName(exprType)) {
+ var text = getPropertyNameFromType(exprType);
var prop = getPropertyOfType(objectLiteralType, text);
if (prop) {
markPropertyAsReferenced(prop, property, rightIsThis);
checkPropertyAccessibility(property, /*isSuper*/ false, objectLiteralType, prop);
}
}
- var exprType = getLiteralTypeFromPropertyName(name);
var elementType = getIndexedAccessType(objectLiteralType, exprType, name);
var type = getFlowTypeOfDestructuring(property, elementType);
return checkDestructuringAssignment(property.kind === 276 /* ShorthandPropertyAssignment */ ? property : property.initializer, type);
@@ -54403,10 +54454,11 @@ var ts;
var parent = node.parent.parent;
var parentType = getTypeForBindingElementParent(parent);
var name = node.propertyName || node.name;
- if (!ts.isBindingPattern(name)) {
- var nameText = ts.getTextOfPropertyName(name);
- if (nameText) {
- var property = getPropertyOfType(parentType, nameText); // TODO: GH#18217
+ if (!ts.isBindingPattern(name) && parentType) {
+ var exprType = getLiteralTypeFromPropertyName(name);
+ if (isTypeUsableAsPropertyName(exprType)) {
+ var nameText = getPropertyNameFromType(exprType);
+ var property = getPropertyOfType(parentType, nameText);
if (property) {
markPropertyAsReferenced(property, /*nodeForCheckWriteOnly*/ undefined, /*isThisAccess*/ false); // A destructuring is never a write-only reference.
checkPropertyAccessibility(parent, !!parent.initializer && parent.initializer.kind === 98 /* SuperKeyword */, parentType, property);
@@ -54763,7 +54815,7 @@ var ts;
? downlevelIteration
? ts.Diagnostics.Type_0_is_not_an_array_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator
: isIterable
- ? ts.Diagnostics.Type_0_is_not_an_array_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators
+ ? ts.Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_Use_compiler_option_downlevelIteration_to_allow_iterating_of_iterators
: ts.Diagnostics.Type_0_is_not_an_array_type
: downlevelIteration
? ts.Diagnostics.Type_0_is_not_an_array_type_or_a_string_type_or_does_not_have_a_Symbol_iterator_method_that_returns_an_iterator
@@ -59405,6 +59457,7 @@ var ts;
if (nodeArguments.length !== 1) {
return grammarErrorOnNode(node, ts.Diagnostics.Dynamic_import_must_have_one_specifier_as_an_argument);
}
+ checkGrammarForDisallowedTrailingComma(nodeArguments);
// see: parseArgumentOrArrayLiteralElement...we use this function which parse arguments of callExpression to parse specifier for dynamic import.
// parseArgumentOrArrayLiteralElement allows spread element to be in an argument list which is not allowed as specifier in dynamic import.
if (ts.isSpreadElement(nodeArguments[0])) {
@@ -61837,22 +61890,62 @@ var ts;
return node;
}
ts.createBundle = createBundle;
- function createUnparsedSourceFile(text, mapPath, map) {
+ function createUnparsedSourceFile(textOrInputFiles, mapPathOrType, map) {
var node = ts.createNode(281 /* UnparsedSource */);
- node.text = text;
- node.sourceMapPath = mapPath;
- node.sourceMapText = map;
+ if (!ts.isString(textOrInputFiles)) {
+ ts.Debug.assert(mapPathOrType === "js" || mapPathOrType === "dts");
+ node.fileName = mapPathOrType === "js" ? textOrInputFiles.javascriptPath : textOrInputFiles.declarationPath;
+ node.sourceMapPath = mapPathOrType === "js" ? textOrInputFiles.javascriptMapPath : textOrInputFiles.declarationMapPath;
+ Object.defineProperties(node, {
+ text: { get: function () { return mapPathOrType === "js" ? textOrInputFiles.javascriptText : textOrInputFiles.declarationText; } },
+ sourceMapText: { get: function () { return mapPathOrType === "js" ? textOrInputFiles.javascriptMapText : textOrInputFiles.declarationMapText; } },
+ });
+ }
+ else {
+ node.text = textOrInputFiles;
+ node.sourceMapPath = mapPathOrType;
+ node.sourceMapText = map;
+ }
return node;
}
ts.createUnparsedSourceFile = createUnparsedSourceFile;
- function createInputFiles(javascript, declaration, javascriptMapPath, javascriptMapText, declarationMapPath, declarationMapText) {
+ function createInputFiles(javascriptTextOrReadFileText, declarationTextOrJavascriptPath, javascriptMapPath, javascriptMapTextOrDeclarationPath, declarationMapPath, declarationMapText) {
var node = ts.createNode(282 /* InputFiles */);
- node.javascriptText = javascript;
- node.javascriptMapPath = javascriptMapPath;
- node.javascriptMapText = javascriptMapText;
- node.declarationText = declaration;
- node.declarationMapPath = declarationMapPath;
- node.declarationMapText = declarationMapText;
+ if (!ts.isString(javascriptTextOrReadFileText)) {
+ var cache_1 = ts.createMap();
+ var textGetter_1 = function (path) {
+ if (path === undefined)
+ return undefined;
+ var value = cache_1.get(path);
+ if (value === undefined) {
+ value = javascriptTextOrReadFileText(path);
+ cache_1.set(path, value !== undefined ? value : false);
+ }
+ return value !== false ? value : undefined;
+ };
+ var definedTextGetter_1 = function (path) {
+ var result = textGetter_1(path);
+ return result !== undefined ? result : "/* Input file " + path + " was missing */\r\n";
+ };
+ node.javascriptPath = declarationTextOrJavascriptPath;
+ node.javascriptMapPath = javascriptMapPath;
+ node.declarationPath = ts.Debug.assertDefined(javascriptMapTextOrDeclarationPath);
+ node.declarationMapPath = declarationMapPath;
+ Object.defineProperties(node, {
+ javascriptText: { get: function () { return definedTextGetter_1(declarationTextOrJavascriptPath); } },
+ javascriptMapText: { get: function () { return textGetter_1(javascriptMapPath); } },
+ declarationText: { get: function () { return definedTextGetter_1(ts.Debug.assertDefined(javascriptMapTextOrDeclarationPath)); } },
+ declarationMapText: { get: function () { return textGetter_1(declarationMapPath); } } // TODO:: if there is inline sourceMap in dtsFile, use that
+ });
+ }
+ else {
+ node.javascriptText = javascriptTextOrReadFileText;
+ node.javascriptMapPath = javascriptMapPath;
+ node.javascriptMapText = javascriptMapTextOrDeclarationPath;
+ node.declarationText = declarationTextOrJavascriptPath;
+ node.declarationMapPath = declarationMapPath;
+ node.declarationMapText = declarationMapText;
+ }
return node;
}
ts.createInputFiles = createInputFiles;
@@ -66203,7 +66296,7 @@ var ts;
function transformBundle(node) {
return ts.createBundle(node.sourceFiles.map(transformSourceFile), ts.mapDefined(node.prepends, function (prepend) {
if (prepend.kind === 282 /* InputFiles */) {
- return ts.createUnparsedSourceFile(prepend.javascriptText, prepend.javascriptMapPath, prepend.javascriptMapText);
+ return ts.createUnparsedSourceFile(prepend, "js");
}
return prepend;
}));
@@ -80436,7 +80529,7 @@ var ts;
return ts.updateSourceFileNode(sourceFile, transformAndReplaceLatePaintedStatements(updated), /*isDeclarationFile*/ true, /*referencedFiles*/ [], /*typeReferences*/ [], /*hasNoDefaultLib*/ false, /*libReferences*/ []);
}), ts.mapDefined(node.prepends, function (prepend) {
if (prepend.kind === 282 /* InputFiles */) {
- return ts.createUnparsedSourceFile(prepend.declarationText, prepend.declarationMapPath, prepend.declarationMapText);
+ return ts.createUnparsedSourceFile(prepend, "dts");
}
}));
bundle.syntheticFileReferences = [];
@@ -81797,16 +81890,21 @@ var ts;
}
ts.forEachEmittedFile = forEachEmittedFile;
/*@internal*/
+ function getOutputPathsForBundle(options, forceDtsPaths) {
+ var outPath = options.outFile || options.out;
+ var jsFilePath = options.emitDeclarationOnly ? undefined : outPath;
+ var sourceMapFilePath = jsFilePath && getSourceMapFilePath(jsFilePath, options);
+ var declarationFilePath = (forceDtsPaths || ts.getEmitDeclarations(options)) ? ts.removeFileExtension(outPath) + ".d.ts" /* Dts */ : undefined;
+ var declarationMapPath = declarationFilePath && ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
+ var bundleInfoPath = options.references && jsFilePath ? (ts.removeFileExtension(jsFilePath) + infoExtension) : undefined;
+ return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: bundleInfoPath };
+ }
+ ts.getOutputPathsForBundle = getOutputPathsForBundle;
+ /*@internal*/
function getOutputPathsFor(sourceFile, host, forceDtsPaths) {
var options = host.getCompilerOptions();
if (sourceFile.kind === 280 /* Bundle */) {
- var outPath = options.outFile || options.out;
- var jsFilePath = options.emitDeclarationOnly ? undefined : outPath;
- var sourceMapFilePath = jsFilePath && getSourceMapFilePath(jsFilePath, options);
- var declarationFilePath = (forceDtsPaths || ts.getEmitDeclarations(options)) ? ts.removeFileExtension(outPath) + ".d.ts" /* Dts */ : undefined;
- var declarationMapPath = declarationFilePath && ts.getAreDeclarationMapsEnabled(options) ? declarationFilePath + ".map" : undefined;
- var bundleInfoPath = options.references && jsFilePath ? (ts.removeFileExtension(jsFilePath) + infoExtension) : undefined;
- return { jsFilePath: jsFilePath, sourceMapFilePath: sourceMapFilePath, declarationFilePath: declarationFilePath, declarationMapPath: declarationMapPath, bundleInfoPath: bundleInfoPath };
+ return getOutputPathsForBundle(options, forceDtsPaths);
}
else {
var ownOutputFilePath = ts.getOwnEmitOutputFilePath(sourceFile.fileName, host, getOutputExtension(sourceFile, options));
@@ -85601,10 +85699,10 @@ var ts;
}
}
/**
- * Skips trivia such as comments and white-space that can optionally overriden by the source map source
+ * Skips trivia such as comments and white-space that can be optionally overridden by the source-map source
*/
function skipSourceTrivia(source, pos) {
- return source.skipTrivia ? source.skipTrivia(pos) : ts.skipTrivia(sourceMapSource.text, pos);
+ return source.skipTrivia ? source.skipTrivia(pos) : ts.skipTrivia(source.text, pos);
}
/**
* Emits a mapping.
@@ -87275,14 +87373,12 @@ var ts;
// Upstream project didn't have outFile set -- skip (error will have been issued earlier)
if (!out)
continue;
- var dtsFilename = ts.changeExtension(out, ".d.ts");
- var js = host.readFile(out) || "/* Input file " + out + " was missing */\r\n";
- var jsMapPath = out + ".map"; // TODO: try to read sourceMappingUrl comment from the file
- var jsMap = host.readFile(jsMapPath);
- var dts = host.readFile(dtsFilename) || "/* Input file " + dtsFilename + " was missing */\r\n";
- var dtsMapPath = dtsFilename + ".map";
- var dtsMap = host.readFile(dtsMapPath);
- var node = ts.createInputFiles(js, dts, jsMap && jsMapPath, jsMap, dtsMap && dtsMapPath, dtsMap);
+ var _a = ts.getOutputPathsForBundle(resolvedRefOpts.options, /*forceDtsPaths*/ true), jsFilePath = _a.jsFilePath, sourceMapFilePath = _a.sourceMapFilePath, declarationFilePath = _a.declarationFilePath, declarationMapPath = _a.declarationMapPath;
+ var node = ts.createInputFiles(function (fileName) {
+ var path = toPath(fileName);
+ var sourceFile = getSourceFileByPath(path);
+ return sourceFile ? sourceFile.text : filesByName.has(path) ? undefined : host.readFile(path);
+ }, jsFilePath, sourceMapFilePath, declarationFilePath, declarationMapPath);
nodes.push(node);
}
}