Skip to content

Commit d566c3b

Browse files
committed
Merge branch 'master' into improve-spread-helper-emit
2 parents e7bfd02 + 3a95f92 commit d566c3b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+4845
-4186
lines changed

Jakefile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ task("importDefinitelyTypedTests", [importDefinitelyTypedTestsJs], function () {
640640

641641
// Local target to build the compiler and services
642642
var tscFile = path.join(builtLocalDirectory, compilerFilename);
643-
compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false);
643+
compileFile(tscFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false, { noMapRoot: true });
644644

645645
var servicesFile = path.join(builtLocalDirectory, "typescriptServices.js");
646646
var servicesFileInBrowserTest = path.join(builtLocalDirectory, "typescriptServicesInBrowserTest.js");

src/compiler/binder.ts

+99-51
Large diffs are not rendered by default.

src/compiler/checker.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -3030,7 +3030,7 @@ namespace ts {
30303030
}
30313031

30323032
function isComputedNonLiteralName(name: PropertyName): boolean {
3033-
return name.kind === SyntaxKind.ComputedPropertyName && !isStringOrNumericLiteral((<ComputedPropertyName>name).expression.kind);
3033+
return name.kind === SyntaxKind.ComputedPropertyName && !isStringOrNumericLiteral((<ComputedPropertyName>name).expression);
30343034
}
30353035

30363036
function getRestType(source: Type, properties: PropertyName[], symbol: Symbol): Type {
@@ -3081,7 +3081,7 @@ namespace ts {
30813081
}
30823082
const literalMembers: PropertyName[] = [];
30833083
for (const element of pattern.elements) {
3084-
if (element.kind !== SyntaxKind.OmittedExpression && !(element as BindingElement).dotDotDotToken) {
3084+
if (!(element as BindingElement).dotDotDotToken) {
30853085
literalMembers.push(element.propertyName || element.name as Identifier);
30863086
}
30873087
}
@@ -4489,6 +4489,8 @@ namespace ts {
44894489
const members: SymbolTable = createMap<Symbol>();
44904490
let stringIndexInfo: IndexInfo;
44914491
let numberIndexInfo: IndexInfo;
4492+
// Resolve upfront such that recursive references see an empty object type.
4493+
setStructuredTypeMembers(type, emptySymbols, emptyArray, emptyArray, undefined, undefined);
44924494
// In { [P in K]: T }, we refer to P as the type parameter type, K as the constraint type,
44934495
// and T as the template type.
44944496
const typeParameter = getTypeParameterFromMappedType(type);
@@ -8927,7 +8929,7 @@ namespace ts {
89278929
return type;
89288930
}
89298931

8930-
function getTypeOfDestructuredProperty(type: Type, name: Identifier | LiteralExpression | ComputedPropertyName) {
8932+
function getTypeOfDestructuredProperty(type: Type, name: PropertyName) {
89318933
const text = getTextOfPropertyName(name);
89328934
return getTypeOfPropertyOfType(type, text) ||
89338935
isNumericLiteralName(text) && getIndexTypeOfType(type, IndexKind.Number) ||
@@ -14221,9 +14223,7 @@ namespace ts {
1422114223
}
1422214224
}
1422314225
else if (property.kind === SyntaxKind.SpreadAssignment) {
14224-
if (property.expression.kind !== SyntaxKind.Identifier) {
14225-
error(property.expression, Diagnostics.An_object_rest_element_must_be_an_identifier);
14226-
}
14226+
checkReferenceExpression(property.expression, Diagnostics.The_target_of_an_object_rest_assignment_must_be_a_variable_or_a_property_access);
1422714227
}
1422814228
else {
1422914229
error(property, Diagnostics.Property_assignment_expected);
@@ -19632,7 +19632,7 @@ namespace ts {
1963219632

1963319633
function isNameOfModuleOrEnumDeclaration(node: Identifier) {
1963419634
const parent = node.parent;
19635-
return isModuleOrEnumDeclaration(parent) && node === parent.name;
19635+
return parent && isModuleOrEnumDeclaration(parent) && node === parent.name;
1963619636
}
1963719637

1963819638
// When resolved as an expression identifier, if the given node references an exported entity, return the declaration

src/compiler/core.ts

+29-1
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ namespace ts {
571571
*/
572572
export function append<T>(to: T[] | undefined, value: T | undefined): T[] | undefined {
573573
if (value === undefined) return to;
574-
if (to === undefined) to = [];
574+
if (to === undefined) return [value];
575575
to.push(value);
576576
return to;
577577
}
@@ -592,6 +592,16 @@ namespace ts {
592592
return to;
593593
}
594594

595+
/**
596+
* Stable sort of an array. Elements equal to each other maintain their relative position in the array.
597+
*/
598+
export function stableSort<T>(array: T[], comparer: (x: T, y: T) => Comparison = compareValues) {
599+
return array
600+
.map((_, i) => i) // create array of indices
601+
.sort((x, y) => comparer(array[x], array[y]) || compareValues(x, y)) // sort indices by value then position
602+
.map(i => array[i]); // get sorted array
603+
}
604+
595605
export function rangeEquals<T>(array1: T[], array2: T[], pos: number, end: number) {
596606
while (pos < end) {
597607
if (array1[pos] !== array2[pos]) {
@@ -816,6 +826,13 @@ namespace ts {
816826
}
817827
}
818828

829+
export function appendProperty<T>(map: Map<T>, key: string | number, value: T): Map<T> {
830+
if (key === undefined || value === undefined) return map;
831+
if (map === undefined) map = createMap<T>();
832+
map[key] = value;
833+
return map;
834+
}
835+
819836
export function assign<T1 extends MapLike<{}>, T2, T3>(t: T1, arg1: T2, arg2: T3): T1 & T2 & T3;
820837
export function assign<T1 extends MapLike<{}>, T2>(t: T1, arg1: T2): T1 & T2;
821838
export function assign<T1 extends MapLike<{}>>(t: T1, ...args: any[]): any;
@@ -2092,6 +2109,17 @@ namespace ts {
20922109
}
20932110

20942111
/** Remove an item from an array, moving everything to its right one space left. */
2112+
export function orderedRemoveItem<T>(array: T[], item: T): boolean {
2113+
for (let i = 0; i < array.length; i++) {
2114+
if (array[i] === item) {
2115+
orderedRemoveItemAt(array, i);
2116+
return true;
2117+
}
2118+
}
2119+
return false;
2120+
}
2121+
2122+
/** Remove an item by index from an array, moving everything to its right one space left. */
20952123
export function orderedRemoveItemAt<T>(array: T[], index: number): void {
20962124
// This seems to be faster than either `array.splice(i, 1)` or `array.copyWithin(i, i+ 1)`.
20972125
for (let i = index; i < array.length - 1; i++) {

src/compiler/diagnosticMessages.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1991,7 +1991,7 @@
19911991
"category": "Error",
19921992
"code": 2700
19931993
},
1994-
"An object rest element must be an identifier.": {
1994+
"The target of an object rest assignment must be a variable or a property access.": {
19951995
"category": "Error",
19961996
"code": 2701
19971997
},

0 commit comments

Comments
 (0)