mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 08:11:30 -06:00
Merge pull request #26017 from ajafff/rest-param-destructuring
allow BindingPattern in FunctionRestParameter
This commit is contained in:
commit
d4055a3234
@ -30004,10 +30004,6 @@ namespace ts {
|
||||
checkGrammarForDisallowedTrailingComma(parameters, Diagnostics.A_rest_parameter_or_binding_pattern_may_not_have_a_trailing_comma);
|
||||
}
|
||||
|
||||
if (isBindingPattern(parameter.name)) {
|
||||
return grammarErrorOnNode(parameter.name, Diagnostics.A_rest_element_cannot_contain_a_binding_pattern);
|
||||
}
|
||||
|
||||
if (parameter.questionToken) {
|
||||
return grammarErrorOnNode(parameter.questionToken, Diagnostics.A_rest_parameter_cannot_be_optional);
|
||||
}
|
||||
|
||||
@ -1350,8 +1350,8 @@ namespace ts {
|
||||
* part of a constructor declaration with a
|
||||
* synthesized call to `super`
|
||||
*/
|
||||
function shouldAddRestParameter(node: ParameterDeclaration | undefined, inConstructorWithSynthesizedSuper: boolean) {
|
||||
return node && node.dotDotDotToken && node.name.kind === SyntaxKind.Identifier && !inConstructorWithSynthesizedSuper;
|
||||
function shouldAddRestParameter(node: ParameterDeclaration | undefined, inConstructorWithSynthesizedSuper: boolean): node is ParameterDeclaration {
|
||||
return !!(node && node.dotDotDotToken && !inConstructorWithSynthesizedSuper);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -1370,11 +1370,11 @@ namespace ts {
|
||||
}
|
||||
|
||||
// `declarationName` is the name of the local declaration for the parameter.
|
||||
const declarationName = getMutableClone(<Identifier>parameter!.name);
|
||||
const declarationName = parameter.name.kind === SyntaxKind.Identifier ? getMutableClone(parameter.name) : createTempVariable(/*recordTempVariable*/ undefined);
|
||||
setEmitFlags(declarationName, EmitFlags.NoSourceMap);
|
||||
|
||||
// `expressionName` is the name of the parameter used in expressions.
|
||||
const expressionName = getSynthesizedClone(<Identifier>parameter!.name);
|
||||
const expressionName = parameter.name.kind === SyntaxKind.Identifier ? getSynthesizedClone(parameter.name) : declarationName;
|
||||
const restIndex = node.parameters.length - 1;
|
||||
const temp = createLoopVariable();
|
||||
|
||||
@ -1439,6 +1439,24 @@ namespace ts {
|
||||
setEmitFlags(forStatement, EmitFlags.CustomPrologue);
|
||||
startOnNewLine(forStatement);
|
||||
statements.push(forStatement);
|
||||
|
||||
if (parameter.name.kind !== SyntaxKind.Identifier) {
|
||||
// do the actual destructuring of the rest parameter if necessary
|
||||
statements.push(
|
||||
setEmitFlags(
|
||||
setTextRange(
|
||||
createVariableStatement(
|
||||
/*modifiers*/ undefined,
|
||||
createVariableDeclarationList(
|
||||
flattenDestructuringBinding(parameter, visitor, context, FlattenLevel.All, expressionName),
|
||||
)
|
||||
),
|
||||
parameter
|
||||
),
|
||||
EmitFlags.CustomPrologue
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -1,23 +0,0 @@
|
||||
tests/cases/conformance/es6/destructuring/iterableArrayPattern14.ts(16,17): error TS2501: A rest element cannot contain a binding pattern.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern14.ts (1 errors) ====
|
||||
class Bar { x }
|
||||
class Foo extends Bar { y }
|
||||
class FooIterator {
|
||||
next() {
|
||||
return {
|
||||
value: new Foo,
|
||||
done: false
|
||||
};
|
||||
}
|
||||
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
function fun(...[a, ...b]) { }
|
||||
~~~~~~~~~
|
||||
!!! error TS2501: A rest element cannot contain a binding pattern.
|
||||
fun(new FooIterator);
|
||||
@ -1,23 +0,0 @@
|
||||
tests/cases/conformance/es6/destructuring/iterableArrayPattern15.ts(16,17): error TS2501: A rest element cannot contain a binding pattern.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern15.ts (1 errors) ====
|
||||
class Bar { x }
|
||||
class Foo extends Bar { y }
|
||||
class FooIterator {
|
||||
next() {
|
||||
return {
|
||||
value: new Foo,
|
||||
done: false
|
||||
};
|
||||
}
|
||||
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
function fun(...[a, b]: Bar[]) { }
|
||||
~~~~~~
|
||||
!!! error TS2501: A rest element cannot contain a binding pattern.
|
||||
fun(...new FooIterator);
|
||||
@ -1,13 +1,10 @@
|
||||
tests/cases/conformance/es6/destructuring/iterableArrayPattern16.ts(1,17): error TS2501: A rest element cannot contain a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/iterableArrayPattern16.ts(2,5): error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type '[Bar, Bar]'.
|
||||
Type 'FooIterator' is missing the following properties from type '[Bar, Bar]': 0, 1, length, pop, and 26 more.
|
||||
tests/cases/conformance/es6/destructuring/iterableArrayPattern16.ts(2,12): error TS2449: Class 'FooIteratorIterator' used before its declaration.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern16.ts (3 errors) ====
|
||||
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern16.ts (2 errors) ====
|
||||
function fun(...[a, b]: [Bar, Bar][]) { }
|
||||
~~~~~~
|
||||
!!! error TS2501: A rest element cannot contain a binding pattern.
|
||||
fun(...new FooIteratorIterator);
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type '[Bar, Bar]'.
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
tests/cases/conformance/es6/destructuring/iterableArrayPattern17.ts(16,17): error TS2501: A rest element cannot contain a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/iterableArrayPattern17.ts(17,5): error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type 'Bar'.
|
||||
Property 'x' is missing in type 'FooIterator' but required in type 'Bar'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern17.ts (2 errors) ====
|
||||
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern17.ts (1 errors) ====
|
||||
class Bar { x }
|
||||
class Foo extends Bar { y }
|
||||
class FooIterator {
|
||||
@ -20,8 +19,6 @@ tests/cases/conformance/es6/destructuring/iterableArrayPattern17.ts(17,5): error
|
||||
}
|
||||
|
||||
function fun(...[a, b]: Bar[]) { }
|
||||
~~~~~~
|
||||
!!! error TS2501: A rest element cannot contain a binding pattern.
|
||||
fun(new FooIterator);
|
||||
~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type 'FooIterator' is not assignable to parameter of type 'Bar'.
|
||||
|
||||
@ -1,23 +0,0 @@
|
||||
tests/cases/conformance/es6/destructuring/iterableArrayPattern20.ts(16,17): error TS2501: A rest element cannot contain a binding pattern.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern20.ts (1 errors) ====
|
||||
class Bar { x }
|
||||
class Foo extends Bar { y }
|
||||
class FooArrayIterator {
|
||||
next() {
|
||||
return {
|
||||
value: [new Foo],
|
||||
done: false
|
||||
};
|
||||
}
|
||||
|
||||
[Symbol.iterator]() {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
function fun(...[[a = new Foo], b = [new Foo]]: Bar[][]) { }
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2501: A rest element cannot contain a binding pattern.
|
||||
fun(...new FooArrayIterator);
|
||||
@ -1,11 +1,8 @@
|
||||
tests/cases/conformance/es6/destructuring/iterableArrayPattern25.ts(1,33): error TS2501: A rest element cannot contain a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/iterableArrayPattern25.ts(2,1): error TS2554: Expected 2 arguments, but got 1.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern25.ts (2 errors) ====
|
||||
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern25.ts (1 errors) ====
|
||||
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]) { }
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2501: A rest element cannot contain a binding pattern.
|
||||
takeFirstTwoEntries(new Map([["", 0], ["hello", 1]]));
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2554: Expected 2 arguments, but got 1.
|
||||
@ -1,12 +1,9 @@
|
||||
tests/cases/conformance/es6/destructuring/iterableArrayPattern26.ts(1,33): error TS2501: A rest element cannot contain a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/iterableArrayPattern26.ts(2,21): error TS2345: Argument of type 'Map<string, number>' is not assignable to parameter of type '[string, number]'.
|
||||
Type 'Map<string, number>' is missing the following properties from type '[string, number]': 0, 1, length, pop, and 22 more.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern26.ts (2 errors) ====
|
||||
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern26.ts (1 errors) ====
|
||||
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { }
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2501: A rest element cannot contain a binding pattern.
|
||||
takeFirstTwoEntries(new Map([["", 0], ["hello", 1]]));
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type 'Map<string, number>' is not assignable to parameter of type '[string, number]'.
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
tests/cases/conformance/es6/destructuring/iterableArrayPattern27.ts(1,33): error TS2501: A rest element cannot contain a binding pattern.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern27.ts (1 errors) ====
|
||||
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { }
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2501: A rest element cannot contain a binding pattern.
|
||||
takeFirstTwoEntries(...new Map([["", 0], ["hello", 1]]));
|
||||
@ -1,11 +1,8 @@
|
||||
tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts(1,33): error TS2501: A rest element cannot contain a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts(2,52): error TS2322: Type 'true' is not assignable to type 'number'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts (2 errors) ====
|
||||
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern28.ts (1 errors) ====
|
||||
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { }
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2501: A rest element cannot contain a binding pattern.
|
||||
takeFirstTwoEntries(...new Map([["", 0], ["hello", true]]));
|
||||
~~~~
|
||||
!!! error TS2322: Type 'true' is not assignable to type 'number'.
|
||||
@ -1,12 +1,9 @@
|
||||
tests/cases/conformance/es6/destructuring/iterableArrayPattern29.ts(1,33): error TS2501: A rest element cannot contain a binding pattern.
|
||||
tests/cases/conformance/es6/destructuring/iterableArrayPattern29.ts(2,21): error TS2345: Argument of type '[string, boolean]' is not assignable to parameter of type '[string, number]'.
|
||||
Type 'boolean' is not assignable to type 'number'.
|
||||
|
||||
|
||||
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern29.ts (2 errors) ====
|
||||
==== tests/cases/conformance/es6/destructuring/iterableArrayPattern29.ts (1 errors) ====
|
||||
function takeFirstTwoEntries(...[[k1, v1], [k2, v2]]: [string, number][]) { }
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2501: A rest element cannot contain a binding pattern.
|
||||
takeFirstTwoEntries(...new Map([["", true], ["hello", true]]));
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
!!! error TS2345: Argument of type '[string, boolean]' is not assignable to parameter of type '[string, number]'.
|
||||
|
||||
@ -1,7 +0,0 @@
|
||||
tests/cases/compiler/restParameterWithBindingPattern1.ts(1,15): error TS2501: A rest element cannot contain a binding pattern.
|
||||
|
||||
|
||||
==== tests/cases/compiler/restParameterWithBindingPattern1.ts (1 errors) ====
|
||||
function a(...{a, b}) { }
|
||||
~~~~~~
|
||||
!!! error TS2501: A rest element cannot contain a binding pattern.
|
||||
@ -2,4 +2,11 @@
|
||||
function a(...{a, b}) { }
|
||||
|
||||
//// [restParameterWithBindingPattern1.js]
|
||||
function a() { }
|
||||
function a() {
|
||||
var _a = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
_a[_i] = arguments[_i];
|
||||
}
|
||||
var a = _a.a, b = _a.b;
|
||||
}
|
||||
//# sourceMappingURL=restParameterWithBindingPattern1.js.map
|
||||
@ -0,0 +1,2 @@
|
||||
//// [restParameterWithBindingPattern1.js.map]
|
||||
{"version":3,"file":"restParameterWithBindingPattern1.js","sourceRoot":"","sources":["restParameterWithBindingPattern1.ts"],"names":[],"mappings":"AAAA,SAAS,CAAC;IAAC,YAAS;SAAT,UAAS,EAAT,qBAAS,EAAT,IAAS;QAAT,uBAAS;;IAAT,IAAI,QAAC,EAAE,QAAC,CAAC;AAAI,CAAC"}
|
||||
@ -0,0 +1,90 @@
|
||||
===================================================================
|
||||
JsFile: restParameterWithBindingPattern1.js
|
||||
mapUrl: restParameterWithBindingPattern1.js.map
|
||||
sourceRoot:
|
||||
sources: restParameterWithBindingPattern1.ts
|
||||
===================================================================
|
||||
-------------------------------------------------------------------
|
||||
emittedFile:tests/cases/compiler/restParameterWithBindingPattern1.js
|
||||
sourceFile:restParameterWithBindingPattern1.ts
|
||||
-------------------------------------------------------------------
|
||||
>>>function a() {
|
||||
1 >
|
||||
2 >^^^^^^^^^
|
||||
3 > ^
|
||||
4 > ^^^^^^^->
|
||||
1 >
|
||||
2 >function
|
||||
3 > a
|
||||
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
|
||||
2 >Emitted(1, 10) Source(1, 10) + SourceIndex(0)
|
||||
3 >Emitted(1, 11) Source(1, 11) + SourceIndex(0)
|
||||
---
|
||||
>>> var _a = [];
|
||||
1->^^^^
|
||||
2 > ^^^^^^^^^^^^
|
||||
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
|
||||
1->(
|
||||
2 > ...{a, b}
|
||||
1->Emitted(2, 5) Source(1, 12) + SourceIndex(0)
|
||||
2 >Emitted(2, 17) Source(1, 21) + SourceIndex(0)
|
||||
---
|
||||
>>> for (var _i = 0; _i < arguments.length; _i++) {
|
||||
1->^^^^^^^^^
|
||||
2 > ^^^^^^^^^^
|
||||
3 > ^^
|
||||
4 > ^^^^^^^^^^^^^^^^^^^^^
|
||||
5 > ^^
|
||||
6 > ^^^^
|
||||
1->
|
||||
2 > ...{a, b}
|
||||
3 >
|
||||
4 > ...{a, b}
|
||||
5 >
|
||||
6 > ...{a, b}
|
||||
1->Emitted(3, 10) Source(1, 12) + SourceIndex(0)
|
||||
2 >Emitted(3, 20) Source(1, 21) + SourceIndex(0)
|
||||
3 >Emitted(3, 22) Source(1, 12) + SourceIndex(0)
|
||||
4 >Emitted(3, 43) Source(1, 21) + SourceIndex(0)
|
||||
5 >Emitted(3, 45) Source(1, 12) + SourceIndex(0)
|
||||
6 >Emitted(3, 49) Source(1, 21) + SourceIndex(0)
|
||||
---
|
||||
>>> _a[_i] = arguments[_i];
|
||||
1 >^^^^^^^^
|
||||
2 > ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
1 >
|
||||
2 > ...{a, b}
|
||||
1 >Emitted(4, 9) Source(1, 12) + SourceIndex(0)
|
||||
2 >Emitted(4, 32) Source(1, 21) + SourceIndex(0)
|
||||
---
|
||||
>>> }
|
||||
>>> var a = _a.a, b = _a.b;
|
||||
1 >^^^^
|
||||
2 > ^^^^
|
||||
3 > ^^^^^^^^
|
||||
4 > ^^
|
||||
5 > ^^^^^^^^
|
||||
6 > ^
|
||||
1 >
|
||||
2 > ...{
|
||||
3 > a
|
||||
4 > ,
|
||||
5 > b
|
||||
6 > }
|
||||
1 >Emitted(6, 5) Source(1, 12) + SourceIndex(0)
|
||||
2 >Emitted(6, 9) Source(1, 16) + SourceIndex(0)
|
||||
3 >Emitted(6, 17) Source(1, 17) + SourceIndex(0)
|
||||
4 >Emitted(6, 19) Source(1, 19) + SourceIndex(0)
|
||||
5 >Emitted(6, 27) Source(1, 20) + SourceIndex(0)
|
||||
6 >Emitted(6, 28) Source(1, 21) + SourceIndex(0)
|
||||
---
|
||||
>>>}
|
||||
1 >
|
||||
2 >^
|
||||
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
|
||||
1 >) {
|
||||
2 >}
|
||||
1 >Emitted(7, 1) Source(1, 25) + SourceIndex(0)
|
||||
2 >Emitted(7, 2) Source(1, 26) + SourceIndex(0)
|
||||
---
|
||||
>>>//# sourceMappingURL=restParameterWithBindingPattern1.js.map
|
||||
@ -1,7 +0,0 @@
|
||||
tests/cases/compiler/restParameterWithBindingPattern2.ts(1,15): error TS2501: A rest element cannot contain a binding pattern.
|
||||
|
||||
|
||||
==== tests/cases/compiler/restParameterWithBindingPattern2.ts (1 errors) ====
|
||||
function a(...[a, b]) { }
|
||||
~~~~~~
|
||||
!!! error TS2501: A rest element cannot contain a binding pattern.
|
||||
@ -2,4 +2,11 @@
|
||||
function a(...[a, b]) { }
|
||||
|
||||
//// [restParameterWithBindingPattern2.js]
|
||||
function a() { }
|
||||
function a() {
|
||||
var _a = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
_a[_i] = arguments[_i];
|
||||
}
|
||||
var a = _a[0], b = _a[1];
|
||||
}
|
||||
//# sourceMappingURL=restParameterWithBindingPattern2.js.map
|
||||
@ -0,0 +1,2 @@
|
||||
//// [restParameterWithBindingPattern2.js.map]
|
||||
{"version":3,"file":"restParameterWithBindingPattern2.js","sourceRoot":"","sources":["restParameterWithBindingPattern2.ts"],"names":[],"mappings":"AAAA,SAAS,CAAC;IAAC,YAAS;SAAT,UAAS,EAAT,qBAAS,EAAT,IAAS;QAAT,uBAAS;;IAAT,IAAI,SAAC,EAAE,SAAC,CAAC;AAAI,CAAC"}
|
||||
@ -0,0 +1,90 @@
|
||||
===================================================================
|
||||
JsFile: restParameterWithBindingPattern2.js
|
||||
mapUrl: restParameterWithBindingPattern2.js.map
|
||||
sourceRoot:
|
||||
sources: restParameterWithBindingPattern2.ts
|
||||
===================================================================
|
||||
-------------------------------------------------------------------
|
||||
emittedFile:tests/cases/compiler/restParameterWithBindingPattern2.js
|
||||
sourceFile:restParameterWithBindingPattern2.ts
|
||||
-------------------------------------------------------------------
|
||||
>>>function a() {
|
||||
1 >
|
||||
2 >^^^^^^^^^
|
||||
3 > ^
|
||||
4 > ^^^^^^^->
|
||||
1 >
|
||||
2 >function
|
||||
3 > a
|
||||
1 >Emitted(1, 1) Source(1, 1) + SourceIndex(0)
|
||||
2 >Emitted(1, 10) Source(1, 10) + SourceIndex(0)
|
||||
3 >Emitted(1, 11) Source(1, 11) + SourceIndex(0)
|
||||
---
|
||||
>>> var _a = [];
|
||||
1->^^^^
|
||||
2 > ^^^^^^^^^^^^
|
||||
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
|
||||
1->(
|
||||
2 > ...[a, b]
|
||||
1->Emitted(2, 5) Source(1, 12) + SourceIndex(0)
|
||||
2 >Emitted(2, 17) Source(1, 21) + SourceIndex(0)
|
||||
---
|
||||
>>> for (var _i = 0; _i < arguments.length; _i++) {
|
||||
1->^^^^^^^^^
|
||||
2 > ^^^^^^^^^^
|
||||
3 > ^^
|
||||
4 > ^^^^^^^^^^^^^^^^^^^^^
|
||||
5 > ^^
|
||||
6 > ^^^^
|
||||
1->
|
||||
2 > ...[a, b]
|
||||
3 >
|
||||
4 > ...[a, b]
|
||||
5 >
|
||||
6 > ...[a, b]
|
||||
1->Emitted(3, 10) Source(1, 12) + SourceIndex(0)
|
||||
2 >Emitted(3, 20) Source(1, 21) + SourceIndex(0)
|
||||
3 >Emitted(3, 22) Source(1, 12) + SourceIndex(0)
|
||||
4 >Emitted(3, 43) Source(1, 21) + SourceIndex(0)
|
||||
5 >Emitted(3, 45) Source(1, 12) + SourceIndex(0)
|
||||
6 >Emitted(3, 49) Source(1, 21) + SourceIndex(0)
|
||||
---
|
||||
>>> _a[_i] = arguments[_i];
|
||||
1 >^^^^^^^^
|
||||
2 > ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
1 >
|
||||
2 > ...[a, b]
|
||||
1 >Emitted(4, 9) Source(1, 12) + SourceIndex(0)
|
||||
2 >Emitted(4, 32) Source(1, 21) + SourceIndex(0)
|
||||
---
|
||||
>>> }
|
||||
>>> var a = _a[0], b = _a[1];
|
||||
1 >^^^^
|
||||
2 > ^^^^
|
||||
3 > ^^^^^^^^^
|
||||
4 > ^^
|
||||
5 > ^^^^^^^^^
|
||||
6 > ^
|
||||
1 >
|
||||
2 > ...[
|
||||
3 > a
|
||||
4 > ,
|
||||
5 > b
|
||||
6 > ]
|
||||
1 >Emitted(6, 5) Source(1, 12) + SourceIndex(0)
|
||||
2 >Emitted(6, 9) Source(1, 16) + SourceIndex(0)
|
||||
3 >Emitted(6, 18) Source(1, 17) + SourceIndex(0)
|
||||
4 >Emitted(6, 20) Source(1, 19) + SourceIndex(0)
|
||||
5 >Emitted(6, 29) Source(1, 20) + SourceIndex(0)
|
||||
6 >Emitted(6, 30) Source(1, 21) + SourceIndex(0)
|
||||
---
|
||||
>>>}
|
||||
1 >
|
||||
2 >^
|
||||
3 > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^->
|
||||
1 >) {
|
||||
2 >}
|
||||
1 >Emitted(7, 1) Source(1, 25) + SourceIndex(0)
|
||||
2 >Emitted(7, 2) Source(1, 26) + SourceIndex(0)
|
||||
---
|
||||
>>>//# sourceMappingURL=restParameterWithBindingPattern2.js.map
|
||||
@ -0,0 +1,36 @@
|
||||
tests/cases/compiler/restParameterWithBindingPattern3.ts(1,16): error TS2322: Type '1' is not assignable to type 'string'.
|
||||
tests/cases/compiler/restParameterWithBindingPattern3.ts(1,23): error TS2322: Type 'true' is not assignable to type 'string'.
|
||||
tests/cases/compiler/restParameterWithBindingPattern3.ts(3,23): error TS1186: A rest element cannot have an initializer.
|
||||
tests/cases/compiler/restParameterWithBindingPattern3.ts(5,30): error TS2493: Tuple type '[boolean, string, number]' of length '3' has no element at index '3'.
|
||||
tests/cases/compiler/restParameterWithBindingPattern3.ts(7,23): error TS2493: Tuple type '[boolean, string, number]' of length '3' has no element at index '3'.
|
||||
tests/cases/compiler/restParameterWithBindingPattern3.ts(9,19): error TS2322: Type '1' is not assignable to type 'boolean'.
|
||||
tests/cases/compiler/restParameterWithBindingPattern3.ts(9,29): error TS2322: Type 'true' is not assignable to type 'string'.
|
||||
tests/cases/compiler/restParameterWithBindingPattern3.ts(9,48): error TS2566: A rest element cannot have a property name.
|
||||
|
||||
|
||||
==== tests/cases/compiler/restParameterWithBindingPattern3.ts (8 errors) ====
|
||||
function a(...[a = 1, b = true]: string[]) { }
|
||||
~
|
||||
!!! error TS2322: Type '1' is not assignable to type 'string'.
|
||||
~
|
||||
!!! error TS2322: Type 'true' is not assignable to type 'string'.
|
||||
|
||||
function b(...[...foo = []]: string[]) { }
|
||||
~
|
||||
!!! error TS1186: A rest element cannot have an initializer.
|
||||
|
||||
function c(...{0: a, length, 3: d}: [boolean, string, number]) { }
|
||||
~
|
||||
!!! error TS2493: Tuple type '[boolean, string, number]' of length '3' has no element at index '3'.
|
||||
|
||||
function d(...[a, , , d]: [boolean, string, number]) { }
|
||||
~
|
||||
!!! error TS2493: Tuple type '[boolean, string, number]' of length '3' has no element at index '3'.
|
||||
|
||||
function e(...{0: a = 1, 1: b = true, ...rest: rest}: [boolean, string, number]) { }
|
||||
~
|
||||
!!! error TS2322: Type '1' is not assignable to type 'boolean'.
|
||||
~
|
||||
!!! error TS2322: Type 'true' is not assignable to type 'string'.
|
||||
~~~~
|
||||
!!! error TS2566: A rest element cannot have a property name.
|
||||
@ -0,0 +1,56 @@
|
||||
//// [restParameterWithBindingPattern3.ts]
|
||||
function a(...[a = 1, b = true]: string[]) { }
|
||||
|
||||
function b(...[...foo = []]: string[]) { }
|
||||
|
||||
function c(...{0: a, length, 3: d}: [boolean, string, number]) { }
|
||||
|
||||
function d(...[a, , , d]: [boolean, string, number]) { }
|
||||
|
||||
function e(...{0: a = 1, 1: b = true, ...rest: rest}: [boolean, string, number]) { }
|
||||
|
||||
//// [restParameterWithBindingPattern3.js]
|
||||
var __rest = (this && this.__rest) || function (s, e) {
|
||||
var t = {};
|
||||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
||||
t[p] = s[p];
|
||||
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
||||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
|
||||
t[p[i]] = s[p[i]];
|
||||
return t;
|
||||
};
|
||||
function a() {
|
||||
var _a = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
_a[_i] = arguments[_i];
|
||||
}
|
||||
var _b = _a[0], a = _b === void 0 ? 1 : _b, _c = _a[1], b = _c === void 0 ? true : _c;
|
||||
}
|
||||
function b() {
|
||||
var _a = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
_a[_i] = arguments[_i];
|
||||
}
|
||||
var _b = _a.slice(0), foo = _b === void 0 ? [] : _b;
|
||||
}
|
||||
function c() {
|
||||
var _a = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
_a[_i] = arguments[_i];
|
||||
}
|
||||
var a = _a[0], length = _a.length, d = _a[3];
|
||||
}
|
||||
function d() {
|
||||
var _a = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
_a[_i] = arguments[_i];
|
||||
}
|
||||
var a = _a[0], d = _a[3];
|
||||
}
|
||||
function e() {
|
||||
var _a = [];
|
||||
for (var _i = 0; _i < arguments.length; _i++) {
|
||||
_a[_i] = arguments[_i];
|
||||
}
|
||||
var _b = _a[0], a = _b === void 0 ? 1 : _b, _c = _a[1], b = _c === void 0 ? true : _c, rest = __rest(_a, [0, 1]);
|
||||
}
|
||||
@ -0,0 +1,27 @@
|
||||
=== tests/cases/compiler/restParameterWithBindingPattern3.ts ===
|
||||
function a(...[a = 1, b = true]: string[]) { }
|
||||
>a : Symbol(a, Decl(restParameterWithBindingPattern3.ts, 0, 0))
|
||||
>a : Symbol(a, Decl(restParameterWithBindingPattern3.ts, 0, 15))
|
||||
>b : Symbol(b, Decl(restParameterWithBindingPattern3.ts, 0, 21))
|
||||
|
||||
function b(...[...foo = []]: string[]) { }
|
||||
>b : Symbol(b, Decl(restParameterWithBindingPattern3.ts, 0, 46))
|
||||
>foo : Symbol(foo, Decl(restParameterWithBindingPattern3.ts, 2, 15))
|
||||
|
||||
function c(...{0: a, length, 3: d}: [boolean, string, number]) { }
|
||||
>c : Symbol(c, Decl(restParameterWithBindingPattern3.ts, 2, 42))
|
||||
>a : Symbol(a, Decl(restParameterWithBindingPattern3.ts, 4, 15))
|
||||
>length : Symbol(length, Decl(restParameterWithBindingPattern3.ts, 4, 20))
|
||||
>d : Symbol(d, Decl(restParameterWithBindingPattern3.ts, 4, 28))
|
||||
|
||||
function d(...[a, , , d]: [boolean, string, number]) { }
|
||||
>d : Symbol(d, Decl(restParameterWithBindingPattern3.ts, 4, 66))
|
||||
>a : Symbol(a, Decl(restParameterWithBindingPattern3.ts, 6, 15))
|
||||
>d : Symbol(d, Decl(restParameterWithBindingPattern3.ts, 6, 21))
|
||||
|
||||
function e(...{0: a = 1, 1: b = true, ...rest: rest}: [boolean, string, number]) { }
|
||||
>e : Symbol(e, Decl(restParameterWithBindingPattern3.ts, 6, 56))
|
||||
>a : Symbol(a, Decl(restParameterWithBindingPattern3.ts, 8, 15))
|
||||
>b : Symbol(b, Decl(restParameterWithBindingPattern3.ts, 8, 24))
|
||||
>rest : Symbol(rest, Decl(restParameterWithBindingPattern3.ts, 8, 37))
|
||||
|
||||
@ -0,0 +1,35 @@
|
||||
=== tests/cases/compiler/restParameterWithBindingPattern3.ts ===
|
||||
function a(...[a = 1, b = true]: string[]) { }
|
||||
>a : (...[a, b]: string[]) => void
|
||||
>a : string
|
||||
>1 : 1
|
||||
>b : string
|
||||
>true : true
|
||||
|
||||
function b(...[...foo = []]: string[]) { }
|
||||
>b : (...[...foo]: string[]) => void
|
||||
>foo : string[]
|
||||
>[] : undefined[]
|
||||
|
||||
function c(...{0: a, length, 3: d}: [boolean, string, number]) { }
|
||||
>c : (__0_0: boolean, __0_1: string, __0_2: number) => void
|
||||
>a : boolean
|
||||
>length : 3
|
||||
>d : undefined
|
||||
|
||||
function d(...[a, , , d]: [boolean, string, number]) { }
|
||||
>d : (__0_0: boolean, __0_1: string, __0_2: number) => void
|
||||
>a : boolean
|
||||
> : undefined
|
||||
> : undefined
|
||||
>d : undefined
|
||||
|
||||
function e(...{0: a = 1, 1: b = true, ...rest: rest}: [boolean, string, number]) { }
|
||||
>e : (__0_0: boolean, __0_1: string, __0_2: number) => void
|
||||
>a : boolean
|
||||
>1 : 1
|
||||
>b : string
|
||||
>true : true
|
||||
>rest : any
|
||||
>rest : { [n: number]: string | number | boolean; 0: boolean; 1: string; 2: number; length: 3; toString(): string; toLocaleString(): string; pop(): string | number | boolean; push(...items: (string | number | boolean)[]): number; concat(...items: ConcatArray<string | number | boolean>[]): (string | number | boolean)[]; concat(...items: (string | number | boolean | ConcatArray<string | number | boolean>)[]): (string | number | boolean)[]; join(separator?: string): string; reverse(): (string | number | boolean)[]; shift(): string | number | boolean; slice(start?: number, end?: number): (string | number | boolean)[]; sort(compareFn?: (a: string | number | boolean, b: string | number | boolean) => number): [boolean, string, number]; splice(start: number, deleteCount?: number): (string | number | boolean)[]; splice(start: number, deleteCount: number, ...items: (string | number | boolean)[]): (string | number | boolean)[]; unshift(...items: (string | number | boolean)[]): number; indexOf(searchElement: string | number | boolean, fromIndex?: number): number; lastIndexOf(searchElement: string | number | boolean, fromIndex?: number): number; every(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => boolean, thisArg?: any): boolean; some(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => boolean, thisArg?: any): boolean; forEach(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => void, thisArg?: any): void; map<U>(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => U, thisArg?: any): U[]; filter<S extends string | number | boolean>(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => value is S, thisArg?: any): S[]; filter(callbackfn: (value: string | number | boolean, index: number, array: (string | number | boolean)[]) => any, thisArg?: any): (string | number | boolean)[]; reduce(callbackfn: (previousValue: string | number | boolean, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => string | number | boolean): string | number | boolean; reduce(callbackfn: (previousValue: string | number | boolean, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => string | number | boolean, initialValue: string | number | boolean): string | number | boolean; reduce<U>(callbackfn: (previousValue: U, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => U, initialValue: U): U; reduceRight(callbackfn: (previousValue: string | number | boolean, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => string | number | boolean): string | number | boolean; reduceRight(callbackfn: (previousValue: string | number | boolean, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => string | number | boolean, initialValue: string | number | boolean): string | number | boolean; reduceRight<U>(callbackfn: (previousValue: U, currentValue: string | number | boolean, currentIndex: number, array: (string | number | boolean)[]) => U, initialValue: U): U; }
|
||||
|
||||
@ -1 +1,3 @@
|
||||
// @sourcemap: true
|
||||
|
||||
function a(...{a, b}) { }
|
||||
@ -1 +1,3 @@
|
||||
// @sourcemap: true
|
||||
|
||||
function a(...[a, b]) { }
|
||||
9
tests/cases/compiler/restParameterWithBindingPattern3.ts
Normal file
9
tests/cases/compiler/restParameterWithBindingPattern3.ts
Normal file
@ -0,0 +1,9 @@
|
||||
function a(...[a = 1, b = true]: string[]) { }
|
||||
|
||||
function b(...[...foo = []]: string[]) { }
|
||||
|
||||
function c(...{0: a, length, 3: d}: [boolean, string, number]) { }
|
||||
|
||||
function d(...[a, , , d]: [boolean, string, number]) { }
|
||||
|
||||
function e(...{0: a = 1, 1: b = true, ...rest: rest}: [boolean, string, number]) { }
|
||||
Loading…
x
Reference in New Issue
Block a user